Java variables declaration
android, java
Solution
Actually `OnCreate()` is the method get called first as you say. The Activity flows like this
`OnCreate` - >`OnStart` -> `OnResume`
At this point the Activity is visible to User
Similarly when Activity ends
`OnPause` -> `OnStop` ->`OnDestroy`
So answering your question. The variables in class level is not dependent, on these methods. Because its scope is for the whole Activity ie; from `OnStart` to `OnDestroy` . You can initialize them in `Oncreate` normally we do so. If you want to change there values on moving to next activity you should do that in `OnResume`. The `Activity` Lifecycle is as follows
You will have all the freedom for the rest as you do in java
Problem
I am a little bit confused about the program flow of an android activity, in java the main method executes first while in android the onCreate methods gets called first, so what about the variables which are defined at class level? How do they get declared/initialized when the activity starts executing, saying that onCreate gets called first. Also Can we initialize these variables in Inner class and use their values outside of the inner class?