Android: Call Function on Appear -
i have app needs every time brought on screen. in oncreate function, app checks user's settings , performs action. in cases, user need change settings in order proceed. how make app call oncreate function again once user returns app? or better yet, function called when view appears? thank you!
this how navigating away app (via button):
if(!networkenabled){ alertdialog alertdialog = new alertdialog.builder(main.this).create(); alertdialog.settitle("network location required"); alertdialog.setmessage("please enable network location settings use app"); alertdialog.setbutton("open", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int which) { intent dialogintent = new intent(android.provider.settings.action_security_settings); dialogintent.addflags(intent.flag_activity_new_task); startactivity(dialogintent); } }); alertdialog.show(); }
and using onstart this:
public void onstart(bundle savedinstancestate) { super.onstart();
check lifecycle of activity. if activity returns background first callback fired onrestart()->onstart()->onresume(). execute code in onstart(). view visible after onstart() called.
edit:
move code onresume() situation. 1 hint better understand lifecycle. override all callbacks of lifecycle
, watch logcat:
public void onstart(bundle savedinstancestate) { super.onstart(); log.w("myactivity","onstart called"); }
Comments
Post a Comment