简体   繁体   English

android:堆栈跟踪以进行销毁

[英]android: stack trace for destroy

My applications main activity is getting "destroyed". 我的应用程序的主要活动是被“破坏”。 I have a Log message in destroy which is getting printed. 我有一个销毁的日志消息正在打印。 But the paths where finish is being called is not getting executed. 但是调用finish的路径没有执行。

So i want to know how can i find out what triggered destroy () to be called. 所以我想知道如何找出触发了destroy()的东西。 Is it finish from my code, or any other system errors. 它是从我的代码还是其他任何系统错误完成的?

@Override
protected void onDestroy() {
    try {
        super.onDestroy();

        Log.i("StartUpActivity", "OnDestroy");
        if (asyncTaskForSync != null && !asyncTaskForSync.isCancelled())
            asyncTaskForSync.cancel(true);
        if (DatabaseManager.getInstance() != null)
            DatabaseManager.getInstance().close();

        if (Utils.imageLoader != null)
            Utils.imageLoader.stopThread();
    } catch (Exception ex) {
        ex.printStackTrace();
    }

}

Note: Answer : I had kept android:noHistory="true" for my startup activity. 注意:回答:我的启动活动保留了android:noHistory =“ true”。 I wanted this page to be not visible again on back press from other activities. 我希望此页面在其他活动的返回新闻中不再显示。 And i had kept all clean up like db close in the destroy of this activity. 在此活动的销毁中,我像db一样关闭了所有清理工作。 SO due to nohistory = true, this activity was automatically getting destryed, leading to all resource closing and thus leading to exceptions in my application. 因此,由于nohistory = true,此活动将自动重试,导致所有资源关闭,从而导致我的应用程序出现异常。

I corrected by removing this flag, and overiding onbackpressed of the second activity. 我通过删除此标志并覆盖第二个活动的onbackpressed进行了更正。

Thanks for your answers 谢谢你的回答

There are several reasons why an activity might be destroyed. 有几种原因可能导致活动被破坏。 Eg if the user rotates the device the default behavior is to destroy the activity and to create a new one. 例如,如果用户旋转设备,则默认行为是销毁该活动并创建一个新活动。

See "Handling configuration changes" here http://developer.android.com/guide/topics/fundamentals/activities.html 请参阅http://developer.android.com/guide/topics/fundamentals/activities.html上的 “处理配置更改”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM