3

我正在創建使用Google GCM服務的應用程序。Android PendingIntent未啓動活動

所以我定義這個功能:

@Override 
protected void onMessage(Context context, Intent intent) 

的onMessage調用一個函數,這是部分代碼:

Intent notificationIntent = new Intent(context,ShowMess.class); 
    notificationIntent.putExtra("id",current_id); 
    notificationIntent.putExtra("cat", cat); 
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    // notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); 
    PendingIntent intent = PendingIntent.getActivity(context, id, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT); 
    notification.setLatestEventInfo(context, title, message, intent); 
    notification.flags |= Notification.FLAG_AUTO_CANCEL; 
    notification.defaults |= Notification.DEFAULT_SOUND; 
    notificationManager.notify(id, notification); 

如果我將消息發送到自己(帶的AsyncTask),但接近快速度的應用程序(後退按鈕)下一個消息將不會啓動活動(ShowMEss.class)爲什麼在你看來?

再見

感謝

+0

PendingIntent intent = PendingIntent.getActivity(context,id,notificationIntent,0);嘗試使用此代碼 –

回答

0

你上面的代碼還沒有註冊的通知。您是否缺少代碼中的以下部分?

NotificationManager notificationManager = 
    (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 

notificationManager.notify(0, notification); 
+0

對不起,我已經省略了代碼的一部分..我只是更新 – Edge7