android - How to navigate to a parent activity -
well when im working on , need configure action bar in app started http://developer.android.com , found looking
public boolean onoptionsitemselected(menuitem item) { switch (item.getitemid()) { // respond action bar's up/home button case android.r.id.home: navutils.navigateupfromsametask(this); return true; } return super.onoptionsitemselected(item);}
ofcourse after adding
<activity android:name="com.example.myfirstapp.displaymessageactivity" android:label="@string/title_activity_display_message" android:parentactivityname="com.example.myfirstapp.mainactivity" > <!-- parent activity meta-data support 4.0 , lower --> <meta-data android:name="android.support.parent_activity" android:value="com.example.myfirstapp.mainactivity" /> </activity>
and the
@override public void oncreate(bundle savedinstancestate) { ... getactionbar().setdisplayhomeasupenabled(true); }
i did of when on program press button in action bar program crashes , here logcat
09-04 12:54:02.087: e/androidruntime(11033): fatal exception: main 09-04 12:54:02.087: e/androidruntime(11033): java.lang.illegalargumentexception: activity legendactivity not have parent activity name specified. (did forget add android.support.parent_activity <meta-data> element in manifest?) 09-04 12:54:02.087: e/androidruntime(11033): @ android.support.v4.app.navutils.navigateupfromsametask(navutils.java:177) 09-04 12:54:02.087: e/androidruntime(11033): @ com.yay.android.projects.stories.legendactivity.onoptionsitemselected(legendactivity.java:44) 09-04 12:54:02.087: e/androidruntime(11033): @ android.app.activity.onmenuitemselected(activity.java:2611) 09-04 12:54:02.087: e/androidruntime(11033): @ com.android.internal.widget.actionbarview$3.onclick(actionbarview.java:206) 09-04 12:54:02.087: e/androidruntime(11033): @ android.view.view.performclick(view.java:4261) 09-04 12:54:02.087: e/androidruntime(11033): @ android.view.view$performclick.run(view.java:17356) 09-04 12:54:02.087: e/androidruntime(11033): @ android.os.handler.handlecallback(handler.java:615) 09-04 12:54:02.087: e/androidruntime(11033): @ android.os.handler.dispatchmessage(handler.java:92) 09-04 12:54:02.087: e/androidruntime(11033): @ android.os.looper.loop(looper.java:137) 09-04 12:54:02.087: e/androidruntime(11033): @ android.app.activitythread.main(activitythread.java:4921) 09-04 12:54:02.087: e/androidruntime(11033): @ java.lang.reflect.method.invokenative(native method) 09-04 12:54:02.087: e/androidruntime(11033): @ java.lang.reflect.method.invoke(method.java:511) 09-04 12:54:02.087: e/androidruntime(11033): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1038) 09-04 12:54:02.087: e/androidruntime(11033): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:805) 09-04 12:54:02.087: e/androidruntime(11033): @ dalvik.system.nativestart.main(native method)
everything said ofcourse have changed activity names corresponding names have what's problem here?
you have set parent activity inside maniifest file
<activity android:name="com.example.mainactivity" android:label="@string/title_activity_main" android:parentactivityname="com.example.mainuiactivity" > <meta-data android:name="android.support.parent_activity" android:value="com.example.sampleactivity" /> </activity>
or use support-v4 follows
navutils.navigateupto(sourceactivity, upintent);
or try solution mentioned in this post
@override public boolean onoptionsitemselected(menuitem item) { switch (item.getitemid()) { case android.r.id.home: intent upintent = new intent(this, yourlistactivity.class); if (navutils.shoulduprecreatetask(this, upintent)) { // activity not part of application's task, // create new task // synthesized stack. taskstackbuilder .from(this) .addnextintent(new intent(this, homeactivity.class)) .addnextintent(upintent).startactivities(); finish(); } else { // activity part of application's task, // navigate hierarchical parent activity. navutils.navigateupto(this, upintent); } return true; } }
this best way android less api level 11
Comments
Post a Comment