Starting app only if its not currently running

后端 未结 11 1716
我寻月下人不归
我寻月下人不归 2020-12-02 23:07

I am sending push notification to users which when clicking on it opens the app.

My problem is that when the app is already open, clicking on the notification start

11条回答
  •  鱼传尺愫
    2020-12-02 23:57

    Use a "launch Intent" for your app, like this:

    PackageManager pm = getPackageManager();
    Intent launchIntent = pm.getLaunchIntentForPackage("your.package.name");
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, launchIntent, 0);
    

    Replace "your.package.name" with the name of your package from the Android manifest.

    Also, you should remove the special launchMode="singleTask" from your manifest. Standard Android behaviour will do what you want.

提交回复
热议问题