android - Navigating back to Parent activity with toolbar -


so break down.

i have 2 activites: main activity , subactivity.

when in subactivity, want press return home button on toolbar , return home.

i tried putting android.support.parent_activity in manifest, still couldn't work. maybe i'm not seeing obvious here. hope guys can help.

here subactivity.

@override     protected void oncreate(bundle savedinstancestate)     {         super.oncreate(savedinstancestate);         setcontentview(r.layout.final_create_cardview_1_image);          //toolbar         mytoolbar = (android.support.v7.widget.toolbar) findviewbyid(r.id.app_bar_pic);         setsupportactionbar(mytoolbar);         getsupportactionbar().sethomebuttonenabled(true);         getsupportactionbar().setdisplayhomeasupenabled(true);       }      private void setsupportactionbar(toolbar mytoolbar)     {      }      @override     public boolean onoptionsitemselected(menuitem item)     {         int id = item.getitemid();         if(id == android.r.id.home)         {             navutils.navigateupfromsametask(this);         }          return super.onoptionsitemselected(item);     } 

now here manifest. first activity being main activity. , second activity being subactivity.

<activity             android:name=".myactivity"             android:label="promenade"             android:parentactivityname=".myactivity">             <meta-data android:name="android.support.parent_activity"                 android:value=".cardfinal.imageactivity">             </meta-data>             <intent-filter>                 <action android:name="android.intent.action.main" />                  <category android:name="android.intent.category.launcher" />             </intent-filter>         </activity>     </activity>         <activity android:name=".cardfinal.imageactivity"             android:label="pickimage">         </activity> 

i'm not quite confident if i'm doing manifest correctly, other solutions on stackoverflow confusing. if can have straight forward answer this, awesome. thanks!

@override public boolean onoptionsitemselected(menuitem item) {     int id = item.getitemid();     if(id == android.r.id.home)     {         //navutils.navigateupfromsametask(this);           finish();     }      return super.onoptionsitemselected(item); } 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -