I have a simple Activity class with an onCreate() method that sets a private boolean field if all initialisation tasks succeed. I read the value of this boolean in other parts of the class.
public class MyActivity extends Activity
{
private boolean initializationSucceeded;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
...
//if everything succeeded...
initializationSucceeded = true;
}
}
Is it necessary to override onSaveInstanceState() to save the state of this boolean, or is what I have fine? I’m afraid I don’t quite know what happens to private field members during all of these activity lifecycle edge cases, so hopefully someone can explain. Thanks.
no need to save it, because everytime onCreate is called and completed initialisationsucceeded will be true. OnCreate is the first thing called after lifecycle events like rotations. Unless you have a thread that is started in onCreate that requires the truth value of initialasationsucceeded then you should be fine.