Android life cycle
where can you define which mainActivity to use?
manifest.xml
when does your application stay in the Created or Start states?
never! after onCreate() finishes, onStart() and onResume() are immediately called
which stage is the entry point of the app?
onCreate()
what is the order of methods being called when switching between activities A and B?
1. onPause() of Activity A 2. onCreate(), onStart() and onResume() of Activity B, giving B focus 3. onStop() of Activity A
how does the system sift through the back stack as the user presses back?
LIFO-wise, steps back through the stack, destroy()ing apps that are popped off
what is a task?
a collection of activities that users interact with when performing a certain job. every task has its own backstack.
review! what's a broadcast receiver again?
a component that receives signals from the phone system (ie battery low, phone turned off, etc)
what happens when the user rotates the screen?
activity gets destroy()ed and restart()ed, giving your activity a chance to load different layouts and shizz
what happens to the app in the Stopped state?
all resources not being used are released. any long-term intensive things that need to be stored in a database should be saved. the state of the user interface stays intact.
what about the Activity gets saved when an activity is called?
any components created with callback methods made during onStart() and onCreate(), the states of any views (ie the text stored in an editText),
how should onResume() be modeled after onPause()?
anything released in onPause() should be reinstantiated in onResume()
what is the expected behavior for how user inputs are saved on mobile?
autosaved without explicit user saving
is onStart() called when an activity is created for the first time or when it is being restarted from the stop state?
both!
what series of function calls happen to restart an app from the stopped state?
first onRestart(), immediately followed by onStart() and onResume()
which function always gets called before onStop()?
onPause()
which function is called as a first indication of the user leaving the activity? (hint! not onStop() or onDestroy())
onPause()
which function is called when the user resumes an app from the paused state?
onResume()
what should you override to specify the things that should get saved if an instance is stopped?
onSaveInstanceState(Bundle savedInstanceState)
which method should you use to reinstantiate resources that were destroyed during onStop()? (hint! not onResume())
onStart(), which is gonna get called anyhow.
where should you check if system requirements are enabled for the app to work?
onStart(), which might be being called for the first time or for the alkdjflkbjth time
which two methods handle how an app is stopped and restarted?
onStop() and onRestart()
which should take the heavier load in terms of saving data, onPause() or onStop()?
onStop() fo sho. onPause() is only for speedy transitions between apps
what should you do when onPause() is called?
save uncommitted changes, stop animations, and stop broadcast receivers
what happens if you don't release memory that might leak in the background during the Stopped state?
system will go ahead and call the onDestroy() function
what's at the top of the activity back stack?
the app that's running in the foreground
what happens to the order of the back stack if a new activity comes to the foreground?
the foreground activity becomes second-to-first, gets stop()ed and saved, and new activity comes to the top
what happens to the Activity instance of the current activity when onStop() is called?
the instance is saved in the memory of the system
what type of information is saved in a bundle automatically for you when an activity is stopped?
the state of each view and the layout
what should you always call when overriding onRestoreInstanceState()
the superclass methodddd ayyyyyye.
what should you always call when overriding the onSaveInstanceState() function?
the superclass methodddd ayyyyyye.
what should you always call when overriding the activity life cycle methods?
the superclass methods (ie super.onResume())
what happens if you don't implement onStop() and onRestart()
usually this is okay! the system usually already saves the activity instance until it is onDestroy()ed anyways.
what happens differently when an app is destroyed because of system constraints from when it's destroyed due to the user pressing BACK?
when due to system constraints, the system will save a Bundle, which is a bunch of data about what the instance of the activity was when the activity shut down.
which user behaviors might destroy() your app?
when the user presses the back button, finish() is called, or the app is not used for a while