如何测试内置保存/恢复的活动的生命周期code? [英] How to test code built to save/restore Lifecycle of an Activity?

查看:106
本文介绍了如何测试内置保存/恢复的活动的生命周期code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何测试以下所有方法code?我要玩的时候所有的人都发生,看看我的code工程活动的保存/恢复过程中的情景。所以,我应该怎么办,在仿真器得到的所有方法进行测试?

 公共类活动来延长的ApplicationContext {
     保护无效的onCreate(包savedInstanceState);

     保护无效的OnStart();

     保护无效onRestoreInstanceState(包savedInstanceState);

     保护无效的onSaveInstanceState(包savedInstanceState);

     保护无效onRestart();

     保护无效onResume();

     保护无效的onPause();

     保护无效的onStop();

     保护无效的onDestroy();
 }
 

解决方案

的onCreate ONSTART onResume 会当你启动应用程序运行时,有不需要进一步的互动。 的onPause 的onStop 的onDestroy 将运行在退出时,例如由$ P $反复pssing后退按钮。

要测试 onRestart 的onSaveInstanceState onRestoreInstanceState ,启动您的应用程序后,尝试pressing主页按钮,启动一些其他的应用程序,以确保您的活动会被杀死,然后重新启动应用程序。

使用记录,检查是否方法被调用。

(活动周期的文档:<一href="http://developer.android.com/guide/topics/fundamentals.html#actlife">http://developer.android.com/guide/topics/fundamentals.html#actlife)

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();
 }

解决方案

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)

这篇关于如何测试内置保存/恢复的活动的生命周期code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆