【发布时间】:2017-04-20 09:23:57
【问题描述】:
这是我的问题:
我有一个包含 3 个活动的应用程序。
-SplashscreenActivity(启动器 - 主)
-登录活动
-HomeActivity
--应用程序被杀死:-- 正常流程:
- 当我通过仪表板图标运行应用程序时,我经历了启动画面(我已登录),然后出现在主页上。 如果我将应用程序置于后台并通过仪表板图标将其启动,我将返回主页。一切正常。
--应用程序被杀死:-- 但是,对于以下过程:
- 我收到推送通知。我通过这个推送运行应用程序,我经历了飞溅,然后来到了家。 但是,如果我将应用程序放在后台,并通过仪表板图标将其启动,我会再次系统地通过启动。这就是问题所在!
这是我的 manifest.xml (EDITED)
<activity
android:name="my.package.SplashscreenActivity"
android:label="@string/app_name"
android:noHistory="false"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name="my.package.LoginActivity"
android:label="@string/app_name"
android:noHistory="false"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize">
</activity>
<activity
android:name="my.package.HomeActivity"
android:label="@string/app_name"
android:noHistory="false"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize">
</activity>
这是我的推送通知 BroadcastReceiver (sendNotificationMethod)
private void sendNotification(String message, String title, int count, String type, long threadId)
{
Activity m_activity;
if (App.getInstance().m_currentActivity != null && App.getInstance().isOnPause())
m_activity = App.getInstance().m_currentActivity;
else
m_activity = null;
PendingIntent pendingIntent = null;
Intent intent = null;
if (m_activity != null)
{
intent = new Intent(this, m_activity.getClass());
intent.putExtra("type", type);
intent.setData((Uri.parse("foobar://" + SystemClock.elapsedRealtime())));
pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
}
else
{
PackageManager pm = getPackageManager();
intent = pm.getLaunchIntentForPackage("my.package");
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("type", type);
pendingIntent = PendingIntent.getActivity(App.getInstance(), 0, intent, 0);
}
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.logo_push_lolilol)
.setColor(App.getInstance().getResources().getColor(R.color.colorPrimary))
.setContentTitle(title)
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(message));
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify((int)threadId, notificationBuilder.build());
}
你有“解决办法”吗?
提前谢谢你。
【问题讨论】:
-
删除这个
android:launchMode="singleTop"。 -
@DheerubhaiBansal 它不会改变任何东西。
标签: java android android-intent push-notification