leonidas79
leonidas79

Reputation: 469

calling an activity from stack instead of launching new instance

how can i call an activity from stack instead of launching new instance ? here is a scenario :

  1. calling activity A with parameters in order to retrieve data
  2. navigate from A to B
  3. navigate from B to C
  4. i want launch A again but not with a new instance , i want get it from the stack so no need to pass parameters and wait to retrieve data.

Upvotes: 1

Views: 108

Answers (2)

Leszek
Leszek

Reputation: 6598

Try to use FLAG_ACTIVITY_REORDER_TO_FRONT. For example:

Intent intent = new Intent(BActivity.this, AActivity.class);     
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);

From javadocs:

public static final int FLAG_ACTIVITY_REORDER_TO_FRONT
Added in API level 3

If set in an Intent passed to Context.startActivity(), this flag will cause the launched activity to be brought to the front of its task's history stack if it is already running.

For example, consider a task consisting of four activities: A, B, C, D. If D calls startActivity() with an Intent that resolves to the component of activity B, then B will be brought to the front of the history stack, with this resulting order: A, C, D, B. This flag will be ignored if FLAG_ACTIVITY_CLEAR_TOP is also specified.

Upvotes: 0

rekire
rekire

Reputation: 47945

If I get your point correctly you can simple exit your activity B and C with finish();.

So if you ActivityC finishes and also ActivityB the ActivityA should come to the front, which should be that what you want.

Upvotes: 1

Related Questions