问题描述
我有一个文本输入框,旋转器输入一个基本的应用程序,以及第二微调输入的阵列取决于在选项菜单中更改设置。
I have a basic app with text inputs, a spinner input, and a second spinner input whose array depends on a setting changed in the Options menu.
目前,当我preSS主页或preSS回报,而在我的应用程序,我要么返回桌面或循环回过旧的投入我把最近。
Currently, when I press Home or press Return while in my app, I either return to the desktop or cycle back through old inputs i put in recently.
我怎样才能prevent无法打开其自身的多个实例,以便有只有一个实例,在任何给定的时间运行,然后我怎么能保存数据输入到输入端,并选择在我的选项的设置我的应用程序菜单?
How can I prevent my app from opening multiple instances of itself so that there is only one instance running at any given time, and then how can I save the data entered into inputs, and the settings chosen in my option menu?
我是一个有点新的爪哇,所以我道歉,如果这是一个简单的问题。
I'm a bit new to Java, so I apologize if this is a simple problem.
推荐答案
在你acticity覆盖的onSaveInstanceState和onRestoreInstanceState。这些方法可以让您将数据保存到捆绑你还可以保存数据 preferences 。在我所有的应用我会覆盖的onSaveInstanceState和onRestoreInstanceState保存和负载值包。我还保存在onResume数据中的onPause preferences和负载preferences。此外,在的onCreate(捆绑savedInstanceState)我不喜欢这样的检查
In your acticity override onSaveInstanceState and onRestoreInstanceState. These methods will allow you to save data into a Bundle You can also save data to Preferences. In all of my applications I override both onSaveInstanceState and onRestoreInstanceState to save and load values to a Bundle. I also save data to preferences in onPause and load preferences in onResume. Also in onCreate(Bundle savedInstanceState) I do a check like this
if(savedInstanceState != null)
{
m_mainView.restoreInstanceState(savedInstanceState);
}
else
{
m_mainView.loadGameFromDatabase(getPreferences(MODE_PRIVATE));
}
这些做法一直为我工作。
These practices have always worked for me.
这篇关于如何退出时保存您的活动的状态?安卓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!