android - Open Application home page after dismissing notification -


upon pressing button, after opening notification, user taken home screen instead of going main page of application. (using samsung s5 android 5.0)

the notification built , shown follows:

notificationmanager mnotifymgr =                     (notificationmanager)getsystemservice(notification_service); intent resultintent = new intent(gcmmessagehandler.this, listviewitemdetailactivity.class);             bundle b = new bundle();             //... put 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 manifest file, have set parentactivity follows

<activity         android:name=".listviewitemdetailactivity"         android:parentactivityname=".mainactivity">         <meta-data             android:name="android.support.parent_activity"             android:value=".mainactivity" /> </activity> 

the simplest thing can pass bool variable form notification e.g**(_is_coming_from_notification)** , in listviewitemdetailactivity activtiy variable , based on if user go open app home page. below code reference.

resultintent.putextra("is_comming_form_notification", true); 

get in activity.

   boolean _is_comming_from_notification = intent.getbooleanextra("is_comming_form_notification", false); 

and in backpressed method

 @override    public void onbackpressed() {         if (_is_comming_from_notification ) {         intent intent = new intent(this, app_home_page.class);         startactivity(intent);        }         super.onbackpressed();    } 

Comments