0

One method is to pass a bundle/store in sharedpreference through which this information is obtained. Is there a method other than such to achieve this? In fragments you can do a getBackStackEntryCount.

suku
  • 10,507
  • 16
  • 75
  • 120

1 Answers1

0

In your Application class, register a listener for Activity life cycle events:

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
            @Override
            public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
                // add to stack                
            }

            @Override
            public void onActivityStarted(Activity activity) {

            }

            @Override
            public void onActivityResumed(Activity activity) {

            }

            @Override
            public void onActivityPaused(Activity activity) {

            }

            @Override
            public void onActivityStopped(Activity activity) {

            }

            @Override
            public void onActivitySaveInstanceState(Activity activity, Bundle outState) {

            }

            @Override
            public void onActivityDestroyed(Activity activity) {
                // remomve from stack
            }
        });
    }
}

Then you just need to keep track of your activities in a list (do not put the Activity itself, put the name or a weak reference to it). You can monitor other events as needed.

Francesc
  • 25,014
  • 10
  • 66
  • 84