启动应用程序只有在其当前没有运行 [英] Starting app only if its not currently running
问题描述
我发送推送通知时,点击它会打开应用程序的用户。
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 the app again.
我只是想,如果它来启动应用程序它不是已在运行。
I only want it to start the app if its not already running.
我使用的通知中待意图:
I am using Pending Intent in the notification:
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, Splash.class), 0);
我看到帖子这不能不使用:
I saw posts which say use:
<activity
android:name=".Splash"
android:launchMode="singleTask"
但事情是,我的跑步应用程序正在运行其他活动则7秒,从应用程序启动后完成,所以应用程序运行时飞溅不是当前活动飞溅
but the thing is that my running app is running other activity then the splash which is finished after 7 seconds from app start, so when the app is running Splash is not the current activity
推荐答案
使用一个启动意图
为您的应用程序,像这样的:
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);
替换your.package.name你的包从Android清单的名称。
Replace "your.package.name" with the name of your package from the Android manifest.
此外,你应该从你的清单中删除特殊 launchMode =singleTask
。标准的Android行为将做你想要的。
Also, you should remove the special launchMode="singleTask"
from your manifest. Standard Android behaviour will do what you want.
这篇关于启动应用程序只有在其当前没有运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!