English 中文(简体)
Android/Morodroid的轮调数据重置
原标题:Data Reset on Rotation in Android/Monodroid

I have a text field which indicates date selected by the user.Also i have provided a button for the user to change the currect date. The problem i am facing is as follows.

1。在“Oncape ”方法中,我已经将文本字段设定为当前日期。当活动创建时,它将显示当前日期。

  1. I use the button and change the date to someother date.

这一切都工作正常..

但当我旋转设备时, 创建中的设备再次被调用, 文本字段被更改为当前设备。 我希望文本字段能保留被选中的用户 。

有办法阻止吗?

最佳回答

屏幕旋转杀死了您的活动, 并导致整个生命周期重新启动 。 发生这种情况时, 在 Create 上仍然可以访问开始活动的原始意图, 某些部件可能保留部分状态( 例如 编辑文本), 但很多动态活动数据将会丢失 。 为了防止这种情况, 请使用 < code> sonSaveInstance State 方法 。 这将允许您在旋转杀死屏幕之前将任何重要数据成员放入捆绑中 。 此捆绑随后将传送到您在 Create 上的参数 < code> saveedInstance State. 这里是此上的 dev文档 :

http://developinger.android.com/reference/android/app/activity.html#onSaveInstance State%28android.os.Bundle%29

在您的情况下, 您会想要通过将日期值作为额外附加值放入捆绑来保存您的日期值。 然后, 在 Create 上, 请检查保存的 Instance State 是否为无效, 表明它包含您的日期并相应处理它。 另外, 请确定如果您在活动生命周期中稍后为此文本设定默认值, 它不会破坏您检索的日期 。

问题回答

您需要在旋转前保存变量。 我认为最好的选择是使用应用程序类作为保存变量的位置, 并在 Pause () 函数中执行 。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签