androidandroid-activityandroid-package-managersactivity-manager

Android get second activity from activity stacks


I have three activity running into application.

FirstActivity.java
SecondActivity.java
ThirdActivity.java

NOw, I am using SINGLE_TASK so all activities are in stacks.

The placing of activities is like.

FirstActivity.java (Top)
SecondActivity.java (below First activity)
ThirdActivity.java (Below Second activity)

Now ,I want to check that Is my SecondActivity is running or not? How can I check that?

I used below things but it return me only topActivity from **RunningInfoClass**.

final ActivityManager activitymgr = (ActivityManager).SystemService(Activity.ACTIVITY_SERVICE);


    List<RunningTaskInfo> activ = activitymgr.getRunningTasks(20);
    for (RunningTaskInfo runningTaskInfo : activ) {
        Logger.d(TAG, ">>>>>>>>>>>>>>>>>>>> " + runningTaskInfo.topActivity.getClassName());



    }

I am not saving any activity stacks for now. Do I need to do ?


Solution

  • I searched for the answer. I found that there is not any other way except to maintain stack for the activity. I need to take care pragmatically those activity are active , pause or resume one.