basics of android activity life cycle functions -
i testing out code shows state activity in
public class activity101activity extends activity { string tag = "lifecycle"; /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // setcontentview(r.layout.main); setcontentview(r.layout.activity_activity101); log.d(tag , "in oncreate() event"); } public void onstart() { super.onstart(); log.d(tag , "in onstart() event"); } public void onrestart() { super.onrestart(); log.d(tag , "in onrestart() event"); } public void onresume() { super.onresume(); log.d(tag , "in onresume() event"); } public void onpause() { super.onpause(); log.d(tag , "in onpause() event"); } public void onstop() { super.onstop(); log.d(tag , "in onstop() event" ); } public void ondestroy() { super.ondestroy(); log.d(tag , "in ondestroy() event"); } }
so see ondestroy() called when press button while activity on screen, , never called otherwise. should running in ground if press home button while activity running. however, if go settings -> apps -> running
can't see on list. mean running in background or not?
again, again, code shows onpause() followed onstop() , onstart() followed onresume(). why defined different functions in android environment , not combined?
once activity goes in backstack, in suspended mode. dont see in running app list. once relaunch such suspended application, comes foreground backstack , starts run. kept in backstack preserve state , resume place got stopped before going in background.
to understand why, onstart needed before onresume follow link below. clear doubts clearly:
Comments
Post a Comment