Android Backpressed上的通知应始终打开默认启动程序活动

Android Backpressed上的通知应始终打开默认启动程序活动,android,android-notifications,Android,Android Notifications,我已经为我的android应用程序实现了gcm通知,带有pendingent,当现在单击通知时,它会将用户带到一个活动,我已经定义了通知类型,将用户切换到其他人的活动,以及当用户按下后退按钮时,我不希望应用程序关闭 我想要的是始终打开启动器活动,当用户从活动通知打开时,该活动在清单中定义。有什么办法可以实现吗?提前谢谢 首先在AndroidManifest.xml中为启动器定义活动层次结构 活动。还可以按如下方式生成通知: Intent resultIntent=新的Intent(这个,res

我已经为我的android应用程序实现了gcm通知,带有
pendingent
,当现在单击通知时,它会将用户带到一个活动,我已经定义了通知类型,将用户切换到其他人的活动,以及当用户按下后退按钮时,我不希望应用程序关闭

我想要的是始终打开启动器活动,当用户从
活动
通知打开时,该活动在清单中定义。有什么办法可以实现吗?提前谢谢

首先在AndroidManifest.xml中为启动器定义活动层次结构 活动。还可以按如下方式生成通知:


Intent resultIntent=新的Intent(这个,resultivity.class);
TaskStackBuilder stackBuilder=TaskStackBuilder.create(此);
addParentStack(ResultActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingEvent ResultPendingEvent=stackBuilder.GetPendingEvent(0,PendingEvent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder=新建NotificationCompat.Builder(此);
builder.setContentIntent(resultPendingContent);
NotificationManager mNotif`在此处输入代码`NotificationManager=
(NotificationManager)getSystemService(上下文通知服务);
mNotificationManager.notify(id,builder.build());

您可以使用具有共享优先级的布尔值来处理您的场景,也可以实现onbackPressed并处理您的场景scenario@UsmanKurd谢谢,是的,你是对的,我在所有活动中处理
onbackpress
事件,但如果可能的话,我想要任何其他解决方案来处理此场景。使用共享优先级处理您也可以使用它
Refer this link :
http://developer.android.com/guide/topics/ui/notifiers/notifications.html#NotificationResponse
    <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());