我正在开发小型Android应用程序,我想在其中集成GCM。我用了一个模块,工作正常。唯一的问题是当我的应用程序打开时,如果我点击通知它重新启动我不想要的应用程序..如果应用程序已经运行我想要的只是显示运行窗口,如果应用程序关闭然后启动应用程序... 在我的模块中,onmessage的代码看起来像
int icon = 0x7f020000;
CharSequence tickerText = new String("app anme: " + hashdata.get("messages"));
long when = System.currentTimeMillis();
CharSequence contentTitle = "app name";
CharSequence contentText = new String(" " + hashdata.get("messages"));
Intent notificationIntent = new Intent(this, GCMIntentService.class);
Intent launcherintent = new Intent("android.intent.action.MAIN");
launcherintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
launcherintent.setComponent(ComponentName.unflattenFromString("com.example/com.example.ExampleActivity"));
launcherintent.addCategory("android.intent.category.LAUNCHER");
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, launcherintent, 0);
Notification notification = new Notification(icon, tickerText, when);
notification.defaults = Notification.DEFAULT_ALL;
notification.flags = Notification.FLAG_AUTO_CANCEL;
notification.setLatestEventInfo(context, contentTitle, contentText,contentIntent);
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
mNotificationManager.notify(1, notification);
如果应用程序关闭,我的模块工作正常..但重新启动已经运行的应用程序,这是不期望的......需要帮助.....谢谢..........