0

我已遵循教程並在我的現有應用程序上實施了GCM推送通知。我已設置Main活動來顯示通知。用戶收到通知,點擊它並在Main活動上顯示通知。問題在於應用程序重新啓動,它每次都顯示通知。推送通知每次在應用程序啓動時顯示

主要活動

public void registerGCM() { 
    .... 
    protected Void doInBackground(Void... params) { 
     ServerUtilities.register(context, uname, uemail, regId); 
    } 
} 

林呼籲MainonCreate活動這個函數來註冊程序。這個過程工作正常。

以下是在onCreate函數外的Main活動中的BoradcaseReceiver代碼。

private final BroadcastReceiver mHandleMessageReceiver = new BroadcastReceiver() 
{ 
    @Override 
    public void onReceive(Context context, Intent intent) 
    { 
     String newMessage = intent.getExtras().getString(EXTRA_MESSAGE); 
     WakeLocker.acquire(getApplicationContext()); 
     Toast.makeText(getApplicationContext(), "New Message: " + newMessage, Toast.LENGTH_LONG).show(); 
     WakeLocker.release(); 
    } 
}; 

當用戶點擊它(正常工作),但它也呈現出通知,每次使用啓動應用程序,只顯示一次通知。我如何防止這種情況?

請讓我知道如果我不夠清楚。 任何幫助將不勝感激。

謝謝!

回答

1

如果我理解你正確你缺少此documentation

添加此ATTRS到您的清單活動標籤之間你的結果活性,即MainActivity(上面詳細信息檢查鏈接)

android:excludeFromRecents="true" 
android:launchMode="singleTask" 
android:taskAffinity="" 

我可以」 t看到你的通知接收機類,所以請確保你設置resultIntent標誌,如

resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 

說明:不要忘記給每一個通知一個唯一的ID

+0

我欣賞評論。編輯完成後,我會盡快與您聯繫。謝謝! – Kevin 2014-10-01 07:25:51

+0

我已經編輯了代碼,正如你所解釋的,即時通訊仍然有相同的問題。這裏是更新後的代碼: Manifest: '''android:name =「Main」android:excludeFromRecents =「true」 GenerateNotification: 'notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);' 能否請你解釋一下如何傳遞唯一ID的通知? – Kevin 2014-10-01 07:58:07

+0

您可以分享您註冊並收到通知的完整代碼 – santalu 2014-10-01 08:04:28

相關問題