Friday, February 15, 2013

How to finish all Activity's running in background in Android

Hello All,

This is very easy solution for this question.


We start from A and now we are on D activity.

We used intent for jump one activity to another.

Note: yet we not use finish...

Means A,B,C is running in background...

So, therefore we need to finish all (A,B,C) activities from activity C.
Step 1 : Save A, B, C activity in static Activity Vector. Create Static class and create Activity Vector.

                 public static Vector<Activity> v_context = new Vector<Activity>();

Step 2 : Write following code in A,B,C activity
               i) VARIABLES_STACK_RANJIT.v_context.add(A.this);
               ii) VARIABLES_STACK_RANJIT.v_context.add(B.this);
               i) VARIABLES_STACK_RANJIT.v_context.add(C.this);

Step 3 : Write final code in D activity

Start loop and finish manually all saved activity.

                 for (int i = 0; i < VARIABLES_STACK.v_context.size(); i++) {
Log.e("Activity :" + i, "finished...");