简体   繁体   中英

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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