2016-01-11 48 views
2

我已經爲我的android應用程序實現了gcm Notification,PendingIntent當用戶現在點擊通知時會將用戶帶到活動中,我已經定義了通知的切換用戶類型到其他人的活動以及用戶按下按鈕應用程序關閉,我不想要的。通知onBackpressed應該打開默認的LAUNCHER活動總是

我想是打開LAUNCHER活動始終這是在清單中定義,當用戶從Activity從通知打開點擊back button。有什麼辦法可以實現它嗎?在此先感謝

+1

你可以使用一個布爾共享prefrences和處理你的場景或可以實現onbackPressed和處理你的場景 –

+0

@UsurKurd謝謝,是的,你是對的我在所有活動中處理'onbackpress'事件,但我想要任何其他解決方案,如果可能的話來處理這種情況 –

+0

處理與共享prefü可以使用,以及 –

回答

2
Refer this link : 
http://developer.android.com/guide/topics/ui/notifiers/notifications.html#NotificationResponse 

首先定義活動層級在AndroidManifest.xml用於發射 activity.Also建立你通知如下:

<activity 
    android:name=".LauncherActivity" 
    android:label="@string/app_name" > 
    <intent-filter> 
     <action android:name="android.intent.action.MAIN" /> 
     <category android:name="android.intent.category.LAUNCHER" /> 
    </intent-filter> 
</activity> 
<activity 
    android:name=".ResultActivity" 
    android:parentActivityName=".LauncherActivity"> 
    <meta-data 
     android:name="android.support.PARENT_ACTIVITY" 
     android:value=".LauncherActivity"/> 
</activity> 

     Intent resultIntent=new Intent(this,ResultActivity.class); 
     TaskStackBuilder stackBuilder=TaskStackBuilder.create(this); 
     stackBuilder.addParentStack(ResultActivity.class); 
     stackBuilder.addNextIntent(resultIntent); 
     PendingIntent resultPendingIntent=stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT); 

     NotificationCompat.Builder builder=new NotificationCompat.Builder(this); 
     builder.setContentIntent(resultPendingIntent); 
     NotificationManager mNotif`enter code here`icationManager= 
     (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); 
     mNotificationManager.notify(id,builder.build()); 
+0

如果您發現有幫助,請接受答案。 –