- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在我的主要 Activity 中有一些代码说
if (savedInstanceState != null) {
mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION);
mFromSavedInstanceState = true;
而且我不太明白 (savedInstanceState)
在此代码中的含义。有人能告诉我这在这种情况下是什么意思吗,因为我有点菜鸟,我想了解代码,以便我可以学习、理解它,甚至在需要时复制它。
最佳答案
引自(http://developer.android.com/training/basics/activity-lifecycle/recreating.html):
There are a few scenarios in which your activity is destroyed due to normal app behavior, such as when the user presses the Back button or your activity signals its own destruction by calling finish(). The system may also destroy your activity if it's currently stopped and hasn't been used in a long time or the foreground activity requires more resources so the system must shut down background processes to recover memory.
此外,如果您将应用程序的状态保存在一个包中(通常是 onSaveInstanceState 中的非持久性动态数据),如果需要重新创建 Activity (例如,方向更改),它可以传回 onCreate,以便您不会丢失这些先验信息。如果未提供数据,则 savedInstanceState 为空。
关于java - (savedInstanceState) 是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28785960/
相当简单的问题,但我无法在任何地方找到明确的答案。 fragment 的savedInstanceState和 fragment 的父activity(或封装 fragment )的savedInst
我在获取 Activity 状态时遇到问题。我有 2 个 Activity :MainActivity 和 Activity2。在 MainActivity 中,我放了一个 editText 和一个
我想在与另一台设备“同步”时获取当前系统时间。因此,此 Activity 通常在同步后立即调用/显示。 目前,当前系统时间是正确的,但我还弹出另一个 Activity 的警报,一旦我完成该 Activ
在 Google Api 示例代码中,他们有一个关于保存状态的非常简单的示例。我需要这个来处理屏幕旋转。 我的问题是我不明白方法 getSavedText() 和 setSaveText() 是从哪里
我有一个秒表应用程序,它只有一项 Activity 。三个按钮启动、停止、重置和一个显示计时器的 TextView 。这是我的代码: public class StopwatchActivity ex
我有一个 ViewPager,其中包含用户输入不同输入的一些 fragment 。其中一个 fragment 包含一个 DatePicker 和一个 TimePicker ,我将其存储(当用户选择了日
如果我没有显式调用 onSaveInstanceState(),当 onCreate 中的 savedInstanceState 不为 null 时,这是可能的吗? 我看到一个选项,当系统在崩溃后重新
所以我的 OnsavedInstanceState 中有这段代码 @Override public void onSaveInstanceState(Bundle savedInstanceState
我正在制作一个 Android 应用程序,但我一直遇到一个奇怪的错误。游戏结束后,如果您点击手机上的“返回”按钮,您将回到完成的游戏并继续玩!! 如何防止这种情况发生?有没有办法删除之前的SavedI
我刚开始使用 Android,我遇到了以下问题: 我正在尝试在打开新 Activity 时保存 InstanceState,并且我需要在 Activity 返回可见状态时恢复该状态。 这是我的 onS
在我的主要 Activity 中有一些代码说 if (savedInstanceState != null) { mCurrentSelectedPosition = save
我是 Android 的新手,我在使用 savedInstanceState 和管理生命周期时遇到了一些麻烦。 http://developer.android.com/guide/topics/fu
我有以下情况: Activity A 启动 Activity B Activity A 调用 onPause、onSaveInstanceState 和 onStop 方法。 在 Activity B
据我了解,Activity 会自动保存 View 的状态,而 EditText 和 TextView 之类的东西会自动恢复它们的状态。 这不适用于可见性吗? 例如:如果默认情况下在 XML 中,我有一
我是 Android 开发的新手,但我对 OOP 概念有一些了解。我正在尝试从 Java 的角度学习 Android。 我了解到第9行onCreate()里面的savedInstanceState是B
因此,Activity.onCreate() 将一个Bundle 作为参数,默认情况下它被称为savedInstanceState。 savedInstanceState 是否在应用更新到较新版本时保
这是我保存的InstaceState 代码: @Override public void onSaveInstanceState(Bundle savedInstanceState) { sa
我在 ViewPager 中有一个 fragment 。 Fragment 包含一个 RecyclerView(想想 ListView)。当用户离开然后返回到 fragment 时,无论用户离开列表的
我只是想通过这个简单的例子来了解 Activity 的生命周期,方法是找出如何取回 SomeIntegers g_values 对象和其中的 ArrayList AnInteger 对象。 事实上,它
我正在使用 onSaveInstanceState 方法来存储和检索 fragment 内的局部变量。我的一个 fragment 中有以下代码(简化): private final SimpleDat
我是一名优秀的程序员,十分优秀!