我已经为我的Android应用程序PendingIntent
实现了gcm通知,当用户点击通知时,用户将进入活动状态,我已经定义了通知切换用户的类型到其他活动以及用户按下后退按钮的时候关闭,我不想要。
我想要打开 LAUNCHER活动,当用户从通知中打开的back button
点击Activity
时,会立即在清单中定义。有没有办法实现它?提前谢谢
答案 0 :(得分:3)
Refer this link : http://developer.android.com/guide/topics/ui/notifiers/notifications.html#NotificationResponse
首先在AndroidManifest.xml中为Launcher定义Activity层次结构 还可以按如下方式构建通知:
<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());