Skip to content Skip to sidebar Skip to footer

Activity Calling Finish In Onpause Crashes During Orientation Change

To preserve resources and prevent memory leaks, I am calling finish() in onPause event whenever app is going from one activity to another. I think it works fine, but when i try to

Solution 1:

You could try the Intent.FLAG_ACTIVITY_NO_HISTORY flag. This will finish your activities as soon as new activity appears in front of them.

You can put this into an intent when you start an activity:

intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);

or you can set it in your manifest so that your activity always carries this flag:

android:noHistory="true"

as an attribute in that activity's <activity ... /> tag.

This way, you can avoid trying to call finish in onPause. I think this is better than trying to figure out exactly when the framework will call finish itself.

Solution 2:

Test if you're Activity is already finishing with this.isFinishing() (where this is your activity) ?

Solution 3:

Just a shot in the dark here, but are you calling super.onPause() in your onPause implementation?

Post a Comment for "Activity Calling Finish In Onpause Crashes During Orientation Change"