Android的 - 横向和纵​​向显示模式之间进行切换,使意向失去价值 [英] Android - switching between landscape and portrait mode makes Intent lose values

查看:212
本文介绍了Android的 - 横向和纵​​向显示模式之间进行切换,使意向失去价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用意图在我的Andr​​oid应用程序的活动之间进行切换。我把数据在Intent用于下一个活动。当我切换横向和纵向模式之间的电话,从意图传递的值都将丢失,我得到一个NullPointerException异常。

I am using Intents to switch between activities in my Android app. I am putting data in the Intent for use in the next activity. When I switch the phone between landscape and portrait modes, the values passed from the intent are lost and I get a NullPointerException.

有人能告诉我什么可能是错误的。

Can someone please tell me what could be wrong.

有很多的code将它张贴完全。但是,如果有人需要看看code特定部分,我可以在这里发布它。

There's a lot of code to post it entirely. But if someone needs to look at specific parts of code, I can post it here.

修改
我解决国家的问题不会被保存。但我面临的另一个问题是,没有在定向之后的屏幕工作的按钮已经被改变。在按钮preSS,我得到这样的警告在LogCat中

Edit
I solved the issue of state not being saved. But another problem I faced is that none of the buttons on the screen work after the orientation has been changed. On button press, I get this warning in LogCat

02-25 23:07:49.190: WARN/WindowManager(58): No window to dispatch pointer action 0

请帮忙。

推荐答案

当您切换方向的活动,并重新创建的onCreate被召回,所以你必须使用束保存当前的状态和恢复的方向变化之后。你可以看到这个动作,如果你只有一个TextView的一个应用程序,并输入文本和改变方向。如果你捆绑你的状态的onCreate就可以遏制这种。这大概也是为什么你以后的方向变化空指针。这是恼人的,因为所有的地狱,但是这是我们不得不忍受。

When you switch orientation the activity is recreated and onCreate is recalled so you have to use the bundle to save your current state and restore after an orientation change. You can see this in action if you have just an app with a TextView and you enter text and change orientation. If you bundle your state for onCreate you can curb this. This is probably also why you have a NullPointer after the orientation changes. It is annoying as all hell but something we have to live with.

这一系列的方向教程和的链接http://androidguys.com/ ?P = 2084>尤其是这第一个应该帮助你理解到底是怎么回事,以及如何成功地维持目前的状态。

This link on a series of orientation tutorials and this first one in particular should help you understand exactly what is going on and how to successfully maintain your current state.

更新:也有轮换的Andr​​oid 上SO 活动启动一个职位,几乎同样的事情交易。

Update: There is also a post on SO Activity restart on rotation Android that deals with almost the same thing.

编辑跟进的问题:

你重新连接的方向变化后,你的点击处理程序?

Did you re-attach your click handlers after the orientation change?

这篇关于Android的 - 横向和纵​​向显示模式之间进行切换,使意向失去价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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