Helper class for managing multiple running embedded activities in the same
process. This class is not normally used directly, but rather created for
you as part of the
ActivityGroup implementation.
private static final String TAG = "LocalActivityManager";
Thread our activities are running in.
The containing activity that owns the activities we create.
The activity that is currently resumed.
id -> record of all known activities.
array of all known activities for easy iterating.
True if only one activity can be resumed at a time
Set to true once we find out the container is finishing.
Current state the owner (ActivityGroup) is in
String ids of running activities starting with least recently used.
Create a new LocalActivityManager for holding activities running within
the given
parent.
- Parameters:
parent the host of the embedded activitiessingleMode True if the LocalActivityManger should keep a maximum
of one activity resumed
if (lastNonConfigurationInstances != null) { instance = lastNonConfigurationInstances.get(r.id);
if (r.activityInfo == null) { mParent, r.id, r.intent, r.activityInfo, r, r.instanceState, instance);
if (r.activity == null) { boolean needState = r.instanceState == null;
r.instanceState = instanceState;
Start a new activity running in the group. Every activity you start
must have a unique string ID associated with it -- this is used to keep
track of the activity, so that if you later call startActivity() again
on it the same activity object will be retained.
When there had previously been an activity started under this id,
it may either be destroyed and a new one started, or the current
one re-used, based on these conditions, in order:
- If the Intent maps to a different activity component than is
currently running, the current activity is finished and a new one
started.
- If the current activity uses a non-multiple launch mode (such
as singleTop), or the Intent has the
android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP flag set, then the current
activity will remain running and its
Activity.onNewIntent() method
called.
- If the new Intent is the same (excluding extras) as the previous
one, and the new Intent does not have the
android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP set, then the current activity
will remain running as-is.
- Otherwise, the current activity will be finished and a new
one started.
If the given Intent can not be resolved to an available Activity,
this method throws android.content.ActivityNotFoundException.
Warning: There is an issue where, if the Intent does not
include an explicit component, we can restore the state for a different
activity class than was previously running when the state was saved (if
the set of available activities changes between those points).
- Parameters:
id Unique identifier of the activity to be startedintent The Intent describing the activity to be started- Returns:
- Returns the window of the activity. The caller needs to take
care of adding this window to a view hierarchy, and likewise dealing
with removing the old window if the activity has changed.
- Throws:
android.content.ActivityNotFoundException
"Activities can't be added until the containing group has been created.");
boolean sameIntent = false;
} else if (r.intent != null) { } else if (r.activityInfo != null) { if (aInfo == r.activityInfo ||
(aInfo.name.equals(r.activityInfo.name) &&
aInfo.packageName.equals(r.activityInfo.packageName))) { if (r.curState == RESUMED && !finish) { Destroy the activity associated with a particular id. This activity
will go through the normal lifecycle events and fine onDestroy(), and
then the id removed from the group.
- Parameters:
id Unique identifier of the activity to be destroyedfinish If true, this activity will be finished, so its id and
all state are removed from the group.- Returns:
- Returns the window that was used to display the activity, or
null if there was none.
Retrieve the Activity that is currently running.
Retrieve the ID of the activity that is currently running.
Return the Activity object associated with a string ID.
return r != null ? r.activity : null;
Restore a state that was previously returned by
saveInstanceState(). This
adds to the activity group information about all activity IDs that had
previously been saved, even if they have not been started yet, so if the
user later navigates to them the correct state will be restored.
Note: This does not change the current running activity, or
start whatever activity was previously running when the state was saved.
That is up to the client to do, in whatever way it thinks is best.
- Parameters:
state a previously saved state; does nothing if this is null- See also:
saveInstanceState()
r.instanceState = astate;
r.instanceState = astate;
"Exception thrown when restoring LocalActivityManager state",
Retrieve the state of all activities known by the group. For
activities that have previously run and are now stopped or finished, the
last saved state is used. For the current running activity, its
Activity.onSaveInstanceState(android.os.Bundle) is called to retrieve its current state.
for (int i=0; i<N; i++) { if ((r.instanceState != null || r.curState == RESUMED)
r.instanceState = childState;
if (r.instanceState != null) { Called by the container activity in its
Activity.onResume() so
that LocalActivityManager can perform the corresponding action on the
activities it holds.
for (int i=0; i<N; i++) { Called by the container activity in its
Activity.onPause() so
that LocalActivityManager can perform the corresponding action on the
activities it holds.
for (int i=0; i<N; i++) { Called by the container activity in its
Activity.onStop() so
that LocalActivityManager can perform the corresponding action on the
activities it holds.
for (int i=0; i<N; i++) { Call onRetainNonConfigurationInstance on each child activity and store the
results in a HashMap by id. Only construct the HashMap if there is a non-null
object to store. Note that this does not support nested ActivityGroups.
for (int i=0; i<N; i++) { if ((r != null) && (r.activity != null)) { if (instanceMap == null) { instanceMap.put(r.id, instance);
Remove all activities from this LocalActivityManager, performing an
Activity.onDestroy() on any that are currently instantiated.
Called by the container activity in its
Activity.onDestroy() so
that LocalActivityManager can perform the corresponding action on the
activities it holds.
for (int i=0; i<N; i++) {