android:销毁的堆栈跟踪
我的应用程序的主要活动是被“破坏”。我有一条正在打印的销毁日志消息。但是调用 finish 的路径没有被执行。
所以我想知道如何找出触发 destroy() 被调用的原因。是我的代码完成的,还是任何其他系统错误。
@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();
}
}
注:回答: 我为我的启动活动保留了 android:noHistory="true" 。我希望此页面在其他活动返回时不再可见。我在销毁此活动时保持了所有清理工作,例如数据库关闭。因此,由于 nohistory = true,此活动会自动失效,导致所有资源关闭,从而导致我的应用程序中出现异常。
我通过删除这个标志并覆盖第二个活动的 onbackpressed 来纠正。
感谢您的回答
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.
So i want to know how can i find out what triggered destroy () to be called. 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. 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. SO due to nohistory = true, this activity was automatically getting destryed, leading to all resource closing and thus leading to exceptions in my application.
I corrected by removing this flag, and overiding onbackpressed of the second activity.
Thanks for your answers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
活动被破坏的原因有多种。例如,如果用户旋转设备,则默认行为是销毁该 Activity 并创建一个新 Activity。
请参阅此处的“处理配置更改”http://developer.android.com/guide/主题/基本原理/activities.html
There are several reasons why an activity might be destroyed. E.g. 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