我有一个包含Google Cloud Message和Phonegap的Android应用。发送,接收完成。 我尝试从通知栏启动我的应用程序。但有问题:
This isn't the root activity. Clearing it and returning to the root activity.
如何解决?
PendingIntent:
Intent notificationIntent = new Intent(this, PushHandlerActivity.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
notificationIntent.putExtra("pushBundle", extras);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
强制主要活动负载
PackageManager pm = getPackageManager();
Intent launchIntent = pm.getLaunchIntentForPackage(getApplicationContext().getPackageName());
startActivity(launchIntent);
当我点击通知时,它运行Intent PushHandlerActivity,而PushHandlerActivity强制主要活动加载。当主要活动加载时,它说“这不是根活动。清除它并返回根活动。”在LogCat中,我的应用程序无法显示:(
答案 0 :(得分:0)
请查找我的代码。它对我来说绝对没问题
Intent notificationIntent = new Intent(context, SplashScreen.class);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// Play default notification sound
notification.defaults |= Notification.DEFAULT_SOUND;
// Vibrate if vibrate is enabled
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(0, notification);
答案 1 :(得分:0)
你有没有尝试改变:
Intent launchIntent = pm.getLaunchIntentForPackage(getApplicationContext().getPackageName());
使用
Intent launchIntent = pm.getLaunchIntentForPackage(<PackageNameOfYourMainActivity>);
它将启动您的PhoneGap主要活动。
我没试过这个,这对我来说看起来很合乎逻辑。