what is the better way to check if the activity is still in the stack in order to call it back ?
Intent i = new Intent(getApplicationContext(),MyClass.class)
You can toggle global variable as indicator inside onCreate()
and onDestory()
of specific class, OR inside onActivityCreated()
and onActivityDestroyed()
of ActivityLifecycleCallbacks.
e.g.:
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
if (activity instanceof YourActivity) {
myGlobalData.setActExist(true);
}
}
@Override
public void onActivityDestroyed(Activity activity) {
if (activity instanceof YourActivity) {
myGlobalData.setActExist(false);
}
}
});