GCM How do I detect if app is open and if so pop up an alert box, instead of normal notification flow?

后端 未结 4 912
猫巷女王i
猫巷女王i 2021-02-03 13:47

I have an app where I want to build 2 different flow\'s in:

  • 1.a App is open on any activity
  • 1.b App show\'s an alertbox where user can choose to go to

4条回答
  •  清酒与你
    2021-02-03 14:19

    Make a class extends Application and implement ActivityLifecycleCallbacks and according to on pause and onResume update a public boolean.

    At the time push received check this Boolean and perform as your requirement.

    Hope this will help you

    public class TestApplication extends Application implements ActivityLifecycleCallbacks{
    boolean applicationOnPause = false;
    @Override
    public void onCreate() {
        super.onCreate();
        registerActivityLifecycleCallbacks(this);
    }
    
    
    
    @Override
    public void onActivityCreated(Activity arg0, Bundle arg1) {
        Log.e("","onActivityCreated");
    
    }
    @Override
    public void onActivityDestroyed(Activity activity) {
        Log.e("","onActivityDestroyed ");
    
    }
    @Override
    public void onActivityPaused(Activity activity) {
        applicationOnPause = true;
        Log.e("","onActivityPaused "+activity.getClass());
    
    }
    @Override
    public void onActivityResumed(Activity activity) {
        applicationOnPause = false;
        Log.e("","onActivityResumed "+activity.getClass());
    
    }
    @Override
    public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
        Log.e("","onActivitySaveInstanceState");
    
    }
    @Override
    public void onActivityStarted(Activity activity) {
        Log.e("","onActivityStarted");
    
    }
    @Override
    public void onActivityStopped(Activity activity) {
        Log.e("","onActivityStopped");
    
    }
    

    }

提交回复
热议问题