user2094075 user2094075 - 6 months ago 30
Android Question

How check if my previous activity exist?

In my app, there are 3 activities and their calling sequence is like this...

Splash activity--->Dashboard Activity--->List Activity

If it goes like this then If I press back button on List activity then it will follow the reverse sequence of above.

There is one requirement where user can navigate to List Activity directly from Splash (Skipping Dashboard Activity) Now when user will hit back button on List Activity then I wan't to show Dashboard Activity which is not there in the Activity Stack.

So please help me with the best approach.

Answer

Pass a boolean through the intent for going to List Activity from either of the others. Using onBackPressed check if the boolean is true or false for skipping Dashboard Activity. Then if true put new intent for loading dashboard activity and finish(); on list activity.