Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The meaning of FLAG_ACTIVITY_SINGLE_TOP in Android

In intent I can set such flag as FLAG_ACTIVITY_SINGLE_TOP. Can somebody explain me its meaning, cause I just don't get it? =)

like image 206
lomza Avatar asked May 04 '11 17:05

lomza


People also ask

What is back stack in Android?

A task is a collection of activities that users interact with when trying to do something in your app. These activities are arranged in a stack—the back stack—in the order in which each activity is opened. For example, an email app might have one activity to show a list of new messages.

How do you use flags on Android?

There are flags which you can use in this time depending on your requirement. Here is how they work : FLAG_ACTIVITY_CLEAR_TASK - If set in any intent that is passed to your startActivity(), it will cause any existing task that would be associated with the activity to be cleared before the activity is started.

What is Flag_activity_clear_top?

flag — FLAG_ACTIVITY_CLEAR_TOP: If the Activity being started is already running in the current task then instead of launching the new instance of that Activity, all the other activities on top of it is destroyed (with call to onDestroy method) and this intent is delivered to the resumed instance of the Activity (now ...


1 Answers

The tasks page says for single top:

If an instance of the activity already exists at the top of the current task, the system routes the intent to that instance through a call to its onNewIntent() method, rather than creating a new instance of the activity. The activity can be instantiated multiple times, each instance can belong to different tasks, and one task can have multiple instances (but only if the the activity at the top of the back stack is not an existing instance of the activity).

For example, suppose a task's back stack consists of root activity A with activities B, C, and D on top (the stack is A-B-C-D; D is on top). An intent arrives for an activity of type D. If D has the default "standard" launch mode, a new instance of the class is launched and the stack becomes A-B-C-D-D. However, if D's launch mode is "singleTop", the existing instance of D is deliverd the intent through onNewIntent(), because it's at the top of the stack—the stack remains A-B-C-D. However, if an intent arrives for an activity of type B, then a new instance of B is added to the stack, even if its launch mode is "singleTop".

like image 92
Hakan Ozbay Avatar answered Sep 29 '22 13:09

Hakan Ozbay