Reputation: 13384
I have three Activities in my Application say A,B and C, Where A is the Login Activity and starts B after login and B later starts Activity C. Now if I am on B or C and the Application goes in background and later Android decides to kill my Application (for what so ever reason). I want to always start from A. However if the Application was not killed I would like to start from the Activity where I left (B or C). How to achieve that ?
I have tried using clearTaskOnLaunch as suggested by so many answers but either that doesn't suit my requirements or I am not using that properly.
Upvotes: 0
Views: 185
Reputation: 495
This is what I used to always start from the 1st Activity
Put this code in your B or C
Intent i=new Intent(getApplicationContext(),A.class);//this will close all activities except A
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.putExtra("exit", true);
startActivity(i);
and in A's OnCreate
if(getIntent().getBooleanExtra("exit", false))
finish(); //This will finish your main activity
Upvotes: 2