How can I test all of the following methods code? I want to play scenarios when all of them are happening to see if my code works for save/restore process of an activity. So what should I do in the Emulator to get all methods tested?
public class Activity extends ApplicationContext { protected void onCreate(Bundle savedInstanceState); protected void onStart(); protected void onRestoreInstanceState(Bundle savedInstanceState); protected void onSaveInstanceState(Bundle savedInstanceState); protected void onRestart(); protected void onResume(); protected void onPause(); protected void onStop(); protected void onDestroy(); }
To test onSaveInstanceState and onRestoreInstanceState you can use either the SetAlwaysFinish tool (see link below) or the DevTools app included with the emulator. Both of these apps use a hidden setting called AlwaysFinish which is part of the ActivityManagerNative class to change the behavior of the Android OS.
The onSaveInstanceState() method allows you to add key/value pairs to the outState of the app. Then the onRestoreInstanceState() method will allow you to retrieve the value and set it back to the variable from which it was originally collected.
As your activity begins to stop, the system calls the onSaveInstanceState() method so your activity can save state information to an instance state bundle.
1. onCreate(): In this state, the activity is created. 2. onStart(): This callback method is called when the activity becomes visible to the user.
If you have enabled Developer Options on your device, there is an option Do not keep activities that will help test onRestoreInstanceState()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With