一个变量的Andr​​oid内部的活动状态 [英] State of variables inside an Android activity

查看:129
本文介绍了一个变量的Andr​​oid内部的活动状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经定义一个全局变量的活动内,根据不同的按钮用户这个变量的变化具有pressed。

I have defined a global variable inside an activity, this variable changes depending on the button user has pressed.

如果我在我的应用程序的用户界面去外面回来按住home键,显示最近的应用程序列表,然后我的变量保持自己的状态,但如果我再由pressing艾康的应用程序运行我的应用程序可变状态消失了。

If I go outside of my app UI and come back by holding the home button which shows the list of recent apps, then my variable keeps its state, but if I run my app again by pressing the app aicon the variable state is gone.

有没有一种方法来保持变量的状态?

Is there a way to keep the state of the variable?

推荐答案

您可以在<保存变量的值href="http://developer.android.com/reference/android/app/Activity.html#onSaveInstanceState%28android.os.Bundle%29"相对=nofollow> 的onSaveInstanceState() 回调。然后,您使用的是通过了冰柱参数和<一href="http://developer.android.com/reference/android/app/Activity.html#onCreate%28android.os.Bundle%29"相对=nofollow> 的onCreate() ,以恢复该值。你可能有兴趣阅读管理活动生命周期

另外请注意,Java有类变量和成员变量而不是全局变量。

Also note that Java has class variables and member variables but not global variables.

这篇关于一个变量的Andr​​oid内部的活动状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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