Search...

Showing posts with label Flag. Show all posts
Showing posts with label Flag. Show all posts

Monday, February 27, 2012

How to go to home activity by removing the in between activities on the stack in android??


Suppose you user went to A->B->C->D activities and now user wanted to again come to activity A(HomeActivity)from D activity. Use the following code.

            Intent intent = new Intent(this, HomeActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);

How to clear task stack to finish all activity in android?


Intent i = new Intent(this MyActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);


startActivity(i);

       finish();


This code will close all the opened activities and start new activity as root one.