Is it okay for me to implement a switch statement in the onCreate method?
I currently have an activity's onCreate() method set to capture an intent
the first thing it does. The intent will always have an extra int
"ACTIONCODE" that determines what the activity should do.
Activity A might want activity Z to set up variables for the first time,
so it calls startActivity(includedIntent) which has some extra int
ActivityZ.SET_UP_FIRST_TIME (which is a constant in Activity Z.) Activity
B might want to change the variables around a bit, so it does a
startActivity(includedIntent) with the intent now including an extra int
ActivityZ.CHANGE_VARIABLES as well as other data to change those
variables.
Activity Z could just be a bunch of textviews that display what its
variables are. Depending on what ACTIONCODE it receives from getIntent(),
it will perform things just as it needs to.
I feel like I have a lot more control over the activities in my app my
doing this, yet I fear as though it might be a really naive and
inefficient implementation. I basically do not trust (nor fully
understand) onStart(),onResume(),onPause(),and onStop(). From what I've
heard, there is no guarantee that an activity will always return back to
onResume(). While it was in its onPause() or onStop() state, it could have
been killed or completely destroyed by the system, and thus would only
return back to onCreate() again. It's the only method that I trust.
I even do all of my data saving from onCreate(). Why? I heard that if an
activity is in onPause() or onStop(), it is liable to be killed, and may
not even finish running through all the lines included in the overridden
onPause() or onStop() method. I don't want to perform a data saving
function from within a method that could abruptly stop!
Is my thinking wrong here? Are my fears irrational? If so, what should I
do instead?
No comments:
Post a Comment