0

Android StartActivity kill the Activity1 first and its ondestroyed should get called. Once this completes then open another activity.

  startActivity(new Intent(Activity1.this, Activity2.class));
                        finish();

even if i call finish first in this scenario Activity1 ondestroy method get call after Activity2 is shown to user. I am looking for proper way where i can be sure that Activity1 get destroyed completely then only show Activity2

Feroz Siddiqui
  • 3,840
  • 6
  • 34
  • 69

2 Answers2

0

You can call finish(), and call startActivity() inside onDestroy():

void onDestroy() {
  startActivity(new Intent(Activity1.this, Activity2.class));
  super.onDestroy();
}
Rediska
  • 1,392
  • 10
  • 14
0

Mabye noHistory atrribute helps you to get rid of this problem

<activity android:name=".ClassName" android:noHistory="true" ... />

also, take a look at this post : Start new Activity and finish current one

mohammad jalili
  • 187
  • 2
  • 10