views:

49

answers:

1

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();
 }
+1  A: 

onCreate, onStart and onResume will run when you start your application, there's no further interaction needed. onPause, onStop and onDestroy will run when you exit, e.g. by pressing the Back button repeatedly.

To test onRestart, onSaveInstanceState and onRestoreInstanceState, after launching your application, try pressing the Home button, launching some other applications to ensure your Activity will be killed, then launch your application again.

Using logging to check whether the methods have been called.

(Activity lifecycle documentation : http://developer.android.com/guide/topics/fundamentals.html#actlife)

molnarm