Bhavin Chauhan
Bhavin Chauhan

Reputation: 2010

Android Activity management

I have one question in mind for activity management. Suppose I have 4 activities say for example A1,A2,A3,A4. Now A1 have one button which start activity A2. A2 have 2 buttons which start either A3 or A4, A3 have 2 buttons which start activity A4 and A1. A4 have 3 buttons to sart activity A1,A2,A3 I do not use finish method in any of this activity. So now user click any of the activity any of the button than check the activity ,that is this already in back ground? If yes than this activity would not generate new instance and start activity which is already in background. otherwise it create new insistence.

Upvotes: 0

Views: 1825

Answers (4)

Pawan Yadav
Pawan Yadav

Reputation: 1782

Intent intent = new Intent();

intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

startActivity(intent);

Upvotes: 1

Yatin Wadhawan
Yatin Wadhawan

Reputation: 66

Whenever the button is clicked in any activity, it creates the new instance of the activity irrespective of the fact the activity is already on the activity stack. Since new Intent is fired every time, it opens new activity. When we press back button then only it goes to the already opened activity from the stack.

Upvotes: 0

wlcw16
wlcw16

Reputation: 1

You can search "android:lunchMode" by Google. Then you will get the anwser.

Upvotes: 0

Barend
Barend

Reputation: 17419

You can get this behaviour by including the FLAG_ACTIVITY_REORDER_TO_FRONT in your Intent's flags and then just calling startActivity(intent) like you normally would.

Upvotes: 5

Related Questions