0

我有一个带有 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 中,我的应用程序无法显示 :(

4

2 回答 2

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);
于 2013-09-20T05:20:43.170 回答
0

您是否尝试更改:

Intent launchIntent = pm.getLaunchIntentForPackage(getApplicationContext().getPackageName());

Intent launchIntent = pm.getLaunchIntentForPackage(<PackageNameOfYourMainActivity>);

它将启动您的 PhoneGap 主要活动。

我没有尝试过,这对我来说看起来很合乎逻辑。

于 2013-11-29T09:46:12.017 回答