navigation - Android navigating up on button click -


i have 2 activities activity , activity b title bar hidden. don't want use navutils.navigateupfromsametask. can go activity activity b on button click. need navigate activity without using intent.

activity_a.xml

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical" >     <button         android:id="@+id/button1"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:text="go activity b" />  </linearlayout> 

activity_b.xml

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <button     android:id="@+id/button2"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:text="go activity a" />  </linearlayout> 

activity_a.java

button button1 = (button) findviewbyid(r.id.button1);  button1.setonclicklistener(new view.onclicklistener() {  @override public void onclick(view arg0) {          intent intent = new intent(context, activity_b.class);         startactivity(intent);         }          }); 

activity_b.java

   protected void oncreate(bundle savedinstancestate) {             super.oncreate(savedinstancestate);             this.requestwindowfeature(window.feature_no_title);             setcontentview(r.layout.avtivity_b);     button button2 = (button) findviewbyid(r.id.button2);          button2.setonclicklistener(new view.onclicklistener() {          @override         public void onclick(view arg0) {               --> code navigate activity <--                    }        });   } 

i have title bar hidden , don't want use navutils or intent.

you call onbackpressed() of activity on buttonclick

button.setonclicklistener(new view.onclicklistener(){     @override     public void onclick(view arg0) {           onbackpressed();      } }); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -