2016-07-19 13 views
0

私のアプリケーションの「ChatActivity」をクリック通知で開始したいのですが、私が戻るボタンをクリックすると、私のアプリケーションの「MainActivity」に行きます。コードをAndroid Notification Guideとして書きます。私のコードは以下の通りです。TaskStackBuilderでの通知についてのAndroidの操作

NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
      NotificationCompat.Builder builder = new NotificationCompat.Builder(context) 
        .setAutoCancel(true) 
        .setCategory(Notification.CATEGORY_MESSAGE) 
        .setContentTitle("你有" + unreadCount + "条新的消息") 
        .setContentText(content) 
        .setNumber((int) unreadCount) 
        //.setColor(Color.RED) 
        .setDefaults(Notification.DEFAULT_ALL) 
        .setSmallIcon(R.mipmap.icon_notify_bold); 
      TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context); 
      Intent resultIntent = new Intent(context, ChatActivity.class); 
      resultIntent.putExtra("to", CommonUtils.removeString(conversation.communicator, 
        ProfileHelper.getProfile().username)); 
      resultIntent.putExtra("conversationId", conversation.id); 
      taskStackBuilder.addParentStack(ChatActivity.class); 
      taskStackBuilder.addNextIntent(resultIntent); 
      PendingIntent resultPendingIntent = taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); 
      builder.setContentIntent(resultPendingIntent); 
      manager.notify(NOTIFY_ID_MESSAGE, builder.build()); 

私のマニフェストXMLは、このようなものです:

<activity 
     android:name=".ui.HomeActivity" 
     android:label="@string/homepage" 
     android:launchMode="singleTask" 
     android:theme="@style/AppTheme.NoActionBar" /> 

    <activity 
     android:name=".ui.ChatActivity" 
     android:label="@string/back" 
     android:launchMode="singleTask" 
     android:parentActivityName=".ui.HomeActivity" 
     android:theme="@style/AppTheme.NoActionBar"> 
     <meta-data 
      android:name="android.support.PARENT_ACTIVITY" 
      android:value=".ui.HomeActivity" /> 
    </activity> 

私の問題は、私はChatActivityに戻るボタンを押したときに、私はすでに私のアプリを開始した場合でも、HomeActivityが再作成されますです。私のアプリを起動してHomeActivityページにいれば、再び作成してはいけないと思う。 HomeActivityを再現するのを避けるには? ご協力いただきありがとうございます。 ChatActivityクラスで

答えて

0

は、次のコードスニペット

@Override 
public boolean onSupportNavigateUp() { 
    onBackPressed(); 
    return true; 
} 
を追加します
関連する問題