Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 我的UI有微调器Edittext。当屏幕关闭时,输入的值将消失。如何保存数据?_Android_Spinner_Screen Off - Fatal编程技术网

Android 我的UI有微调器Edittext。当屏幕关闭时,输入的值将消失。如何保存数据?

Android 我的UI有微调器Edittext。当屏幕关闭时,输入的值将消失。如何保存数据?,android,spinner,screen-off,Android,Spinner,Screen Off,即使在屏幕关闭后,如何显示其中的数据。我了解到我们可以使用共享首选项。但我在许多屏幕中有太多的edittext和微调器。我还使用了异步类,因此获取数据和返回数据需要很多时间。因此,当屏幕关闭时,整个活动将再次重新启动。我在微调器和编辑文本中所做的选择将关闭。因此,我认为最好在应用程序运行时保持屏幕打开,因为我们使用异步任务。如何在应用程序运行时保持屏幕打开 this.getWindow().setFlags(this.getWindow().getFlags() & ~WindowMan

即使在屏幕关闭后,如何显示其中的数据。我了解到我们可以使用共享首选项。但我在许多屏幕中有太多的edittext和微调器。我还使用了异步类,因此获取数据和返回数据需要很多时间。因此,当屏幕关闭时,整个活动将再次重新启动。我在微调器和编辑文本中所做的选择将关闭。因此,我认为最好在应用程序运行时保持屏幕打开,因为我们使用异步任务。如何在应用程序运行时保持屏幕打开

this.getWindow().setFlags(this.getWindow().getFlags() & ~WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
如何避免此屏幕重新启动并将值保留在微调器和EditText中?

尝试使用

在onCreate和onResume中检查捆绑包是否为空,并在onStop或onDestroy中设置捆绑包中的值

这会解决你的问题

你可以这样使用它

Intent intent = new
Intent(getApplicationContext(),SecondActivity.class);
intent.putExtra("Key",Value);  
startActivity(intent);
Bundle extras = intent.getExtras(); 
String tmp = extras.getString("Key");
现在可以像这样获得传递的值

Intent intent = new
Intent(getApplicationContext(),SecondActivity.class);
intent.putExtra("Key",Value);  
startActivity(intent);
Bundle extras = intent.getExtras(); 
String tmp = extras.getString("Key");

无论应用程序的当前状态如何,都不能假定用户不会关闭屏幕。屏幕关闭不会导致活动重新启动。屏幕旋转可能(在这种情况下,关闭“活动重新启动”可能是一个答案),但不关闭屏幕。当屏幕进入关闭状态时,请在调用暂停和停止功能时再粘贴一些代码。