0

GCMを統合したい小さなAndroidアプリケーションを開発しています。私はそれに1つのモジュールを使用し、正常に動作しました。唯一の問題は、アプリケーションが開いているときであり、通知をクリックすると、不要なアプリケーションが再起動されることです。アプリケーションが既に実行されている場合は、実行中のウィンドウを表示し、アプリケーションが閉じている場合はアプリケーションを起動します... onmessage received の私のモジュールコードでは、次のようになります

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);

アプリケーションが閉じられている場合、私のモジュールは正常に動作しています..しかし、予期されていないすでに実行されているアプリケーションを再起動します......助けが必要.....ありがとう.....

4

1 に答える 1

1

Gcm の実装については、これが最適なチュートリアルであり、あなたにも役立つ可能性があります。 Android 用 Google クラウド メッセージング (GCM) の簡単なチュートリアル

于 2012-09-18T07:18:30.157 に答える