简体   繁体   中英

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM