Android - Show fragment on resume -


i have navigation drawer, has few fragments (home, help, about) in activity. on startup opens home. issue i'm having when go fragment such , proceed put phone sleep , subsequently turn on phone on it'll return home instead of help.

i'm quite new lifecycles hoping feedback on how resume different fragment.

edit: provided relevant code update: realised happens because reinit views on resume.

@override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      initializeui(); }   private void initializeui() {       fragabout = new about();     fraghelp = new help();     fraghome = new myviewpager();       // adding fragments activity     fragmentmanager fragmentmanager = getsupportfragmentmanager();      fragmenttransaction transaction = fragmentmanager.begintransaction();     transaction.add(r.id.main_activity_fraglayout, fraghome);      transaction.commit();      ...   }  private void adddraweritems() {      ...      draweritemadapter draweradapter = new draweritemadapter(this, r.layout.nav_list_row, draweritems);     mdrawerlist.setadapter(draweradapter);      mdrawerlist.setonitemclicklistener(new adapterview.onitemclicklistener() {         @override         public void onitemclick(adapterview<?> parent, view view, int position, long id) {             switch (position) {                 case 0:                     ...                     newfragonclick(fraghome, "home");                     break;                 case 1:                     ...                     newfragonclick(fragsettings, "help");                     break;                 case 2:                     ...                     newfragonclick(fragabout, "about");                     break;                 default:                     break;              }         }     }); }  private void newfragonclick(fragment frag, string actionbartitle){      fragmentmanager fragmentmanager = getsupportfragmentmanager();     fragmenttransaction transaction = fragmentmanager.begintransaction();      transaction.replace(r.id.main_activity_fraglayout, frag);     transaction.commit(); } 

use sharedpreferences save current tab position , in onresume() use move saved position.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -