Android的 - 是休闲娱乐的活动期间pserved意图$ P $? [英] Android - Is the intent preserved during activity recreation?

查看:156
本文介绍了Android的 - 是休闲娱乐的活动期间pserved意图$ P $?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个Android应用程序,并且想问如果开始一个活动(这是通过在 getIntent()方式访问)的意图活动休闲期间保存/ preserved如设备的方向,或只是一个事实,即机器人可以删除应用程序的状态,如果它是在后台和重建它(如果是内存不足)?

这是说明问题的一个简单的例子:

在应用程序启动活动的 A 。然后用户点击启动新活动的按钮。活动的 A 已发送到活动的字符串的 X 与值您好通过的意图(使用<强> putExtra 方式)。

在活动的,我可以通过检索意图(通过 getIntent()方式)来检索字符串的 X 的内容,然后检索字符串内容(通过 getStringExtra 方式)。

我是否仍然可以检索意图额外的字符串,甚至意图本身如果该活动是重新创建由于设备旋转,...?

或者我应该保存在的onSaveInstanceState 方式额外的字符串?

我已经试过设备轮换方案,并意图(有额外的字符串一起)始终可以访问。


解决方案

  

我是否仍然可以检索意图额外的字符串,甚至意图本身如果该活动是因重建于设备旋转


是的。您将有相同的意图(或者,至少,副本的意图)的配置变化后你配置更改之前了。

I am building an android application, and would like to ask if the intent that started an activity (which is reachable via the getIntent () method) is saved / preserved during activity recreation such as a device orientation, or simply the fact that android can erase the application state if it is in the background and rebuild it (if it is low on memory) ?

This is a quick example that illustrates the question :

The application launches activity A. Then the user clicks on a button that starts a new activity B. Activity A has sent to activity B a string X with the value Hello via the intent (using the putExtra method).

In activity B, I can retrieve the content of string X by retrieving the intent (via the getIntent () method) and then retrieving the string content (via the getStringExtra method).

Will I still be able to retrieve the extra string from intent, or even the intent itself if the activity is recreated due to device rotation, ... ?

Or should I save the extra string in the onSaveInstanceState method ?

I have tried the device rotation scenario, and the intent (along with the extra string) are always accessible.

解决方案

Will I still be able to retrieve the extra string from intent, or even the intent itself if the activity is recreated due to device rotation

Yes. You will have the same Intent (or, at least, a copy of the Intent) after the configuration change as you had before the configuration change.

这篇关于Android的 - 是休闲娱乐的活动期间pserved意图$ P $?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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