Reputation: 373
Upon pressing the back button, after opening the notification, the user is taken back to the Home screen instead of going back to the main page of the application. (Using a Samsung S5 with Android 5.0)
The notification is built and shown as follows:
NotificationManager mNotifyMgr =
(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Intent resultIntent = new Intent(GcmMessageHandler.this, ListViewItemDetailActivity.class);
Bundle b = new Bundle();
//... put some data
resultIntent.putExtras(b);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(GcmMessageHandler.this);
stackBuilder.addParentStack(ListViewItemDetailActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(GcmMessageHandler.this)
.setContentTitle("Notification")
.setSmallIcon(R.drawable.common_signin_btn_icon_dark)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setContentIntent(resultPendingIntent)
.setPriority(0)
.setContentText(title);
mNotifyMgr.notify(mNotificationId++, mBuilder.build());
Also in the Manifest file, i have set the parentActivity as follows
<activity
android:name=".ListViewItemDetailActivity"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
Upvotes: 2
Views: 101
Reputation: 2885
The simplest thing that you can do is pass the bool variable form your notification e.g**(_Is_Coming_From_notification)** and in your ListViewItemDetailActivity activtiy get that variable and based on that if user go back open your app home page. below is some code for your reference.
resultIntent.putExtra("is_Comming_Form_Notification", true);
get that in your activity.
boolean _Is_Comming_From_Notification = intent.getBooleanExtra("is_Comming_Form_Notification", false);
and in your BackPressed method
@Override
public void onBackPressed() {
if (_Is_Comming_From_Notification ) {
Intent intent = new Intent(this, App_Home_Page.class);
startActivity(intent);
}
super.onBackPressed();
}
Upvotes: 3