我有一个activity ( Whatever.java ),我想在Whatever.java中调用一个在MainActivity中写的受保护的onDestroy方法。
onDestroy MainActivity.java的方法是:
/** The final call you receive before your activity is destroyed. */
protected void onDestroy() {
DebugLog.LOGD("ImageTargets::onDestroy");
super.onDestro
我在我的ListActivity中使用了以下代码
// a separate class in project
public class MyActivity extends ListActivity {
// some common functions here..
}
public class SelectLocation extends MyListActivity {
public void onCreate(Bundle savedInstance) {
// here.....
}
@Override
protected
Android要求所有的Activity子类从它们的生命周期方法中调用超级方法。如果不调用超方法,则会引发异常。为什么Android使用RuntimeException机制来强制调用超方法。为什么它不使用“模板”设计模式,以便在子方法之前自动执行超级方法。例如,可以按如下方式处理onDestroy():
Class Activity{
public void onDestroyFrmwork()
{
//do whatever the super onDestroy() method has to do
onDestroy()
我想知道,在活动再创造、片段再创造或服务再创造的过程中,是否有可能重复使用同一个类的实例?
例如
//public class HomeFragment extends Activity {
//public class HomeFragment extends Service {
public class HomeFragment extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
我有带有线程的服务,从activity中我调用了start service(from Activity::onDestroy())和stop service (activity::onCreate())。
StopService()立即返回,但我的Service::OnDestroy调用了这么多次,非常晚,为什么?如何在调用StopService()时立即调用Service::OnDestroy。
活动类
MyActivity::OnDestroy()
{
System.out.println("MyActivity-OnDestroy Start");
// we a
我有一个磁盘缓存,我需要在应用程序关闭时关闭它。在哪里做这件事最好呢?
-Overriding活动的onDestroy方法,并检查它是否是任务根:
@Override
protected void onDestroy () {
if (this.isTaskRoot()) {
//I only want to close it if this is the last activity of the app
CloseCache();
}
super.onDestroy();
另一个问题是,当我试图通过stopService(intent)将其从主活动中停止时;然后调用了onDestroy方法,但带循环的线程仍在继续
。。有人能帮帮我吗?
*对不起,我的英语-没有母语:D
public class NotificationService extends Service {
final private class MyThread implements Runnable {
int service_id;
MyThread(int service_id) {
this.service_id = se
onDestroy()并不总是被调用。如果调用,则只执行部分代码。大多数时候,在LogCat中,我只看到一条信息:"gps状态在摧毁中被称为第一“。为什么会这样呢?
protected void onDestroy() {
super.onDestroy();
Log.d("on destroy called", "gps state on destroy called first");
editor.putBoolean("gpsOn", false);
Log.d("on destroy ca