Android OnNewIntent not called

后端 未结 3 1798
旧巷少年郎
旧巷少年郎 2020-12-10 04:48

I saw several approaches and I tried everything but couldnt make it work.I dont know why it is so complicated, in the docs it looks so easy! I want to trigger the OnNewInten

3条回答
  •  囚心锁ツ
    2020-12-10 04:51

    As first, you should add android:launchMode="singleTop" to your activity definition in manifest file like below

    
    

    Then like Hasan Masud said that, you should add Intent.ACTION_MAIN and Intent.CATEGORY_LAUNCHER to your action like below

    Intent intent = new Intent(this, MainActivity.class);
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    

    That's all. With this way, if the app is open and when you click the notification, onNewIntent(..) method will trigger but whatever happens, if the app is close, when you click the notification, notification intent will go to the onCreate(..) method of current Activity.

提交回复
热议问题