Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test code built to save/restore Lifecycle of an Activity?

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();  } 
like image 350
Pentium10 Avatar asked Mar 28 '10 16:03

Pentium10


People also ask

How do I test onSaveInstanceState?

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.

What is onSaveInstanceState () and onRestoreInstanceState () in activity?

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.

Which method is be called to allow the activity to save per instance state?

As your activity begins to stop, the system calls the onSaveInstanceState() method so your activity can save state information to an instance state bundle.

What is the first call back method during activity life cycle in Android?

1. onCreate(): In this state, the activity is created. 2. onStart(): This callback method is called when the activity becomes visible to the user.


1 Answers

If you have enabled Developer Options on your device, there is an option Do not keep activities that will help test onRestoreInstanceState().

Android Settings panel

like image 146
user338519 Avatar answered Sep 30 '22 16:09

user338519