强制的Andr​​oid不重绘的方向变化的活动 [英] Forcing Android to not redraw activity on orientation change

查看:103
本文介绍了强制的Andr​​oid不重绘的方向变化的活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经走得加加摸不着头脑。
虽然我也读了不少,关于取向变化,机器人杀死的活动,并启动它作为一个新鲜的,而且要处理,这是保存所有里面的东西的onSaveInstanceState(),并尝试在的onCreate恢复它()

I have been going gaga to figure this out.
Although I have read a lot that on Orientation Change, Android kills an activity and starts it as a fresh one, and the only way to handle this is to save all the stuff inside onSaveInstanceState() and try to restore it inside onCreate().

但我的活动做了很多不同种类的在不同的时间,如果当正在执行网络活动的方向改变网络的活动,我将不得不处理很多不同的,复杂的场景。

But my activity does a lot and different kind of network activities at different times and if the orientation is changed when the network activity is being performed, I'll have to handle a lot of different and complex scenarios.

时那里只是点的Andr​​oid,这项活动并不需要在所有被重绘时,方向改变,这样它会自动保存所有的数据,并没有简单的方法重新使用它?

Is there any simple way to just point Android that this activity doesn't need to be redrawn at all when the orientation is changed so that it automatically saves all the data and re-uses it?

我不知道是否有这样的任何东西。

I wonder if there's any thing like that.

推荐答案

是的,你可以添加属性安卓configChanges =定向在活动中声明的Andr​​oidManifest.xml 文件。

Yes, you can add attribute android:configChanges="orientation" to the activity declaration in the AndroidManifest.xml file.

修改: 在机器人的目的:configChanges 属性是prevent从什么时候真的有必要再创造活动。例如,摄像头应用程序使用此属性,因为它在改变方向时发生的摄像头preVIEW屏幕不得重新创建。用户希望相机preVIEW在没有任何延误工作,当他们转动他们的设备和摄像头的初始化并不是一个非常快的过程。因此,它是一种您的相机应用程序来处理取向的原生行为手动更改。

EDIT: The purpose of the android:configChanges attribute is to prevent an activity from being recreated when it's really necessary. For example the Camera application uses this attribute because it the camera preview screen mustn't be recreated when an orientation change happens. Users expect the camera preview to work without any delays when they rotate their devices and camera initialization is not a very fast process. So it's kind of a native behavior for the Camera application to handle orientation changes manually.

对于大多数应用来说并不重要,如果活动期间取向的变化重新与否。但有时它更方便在此过程中,因为活动缓慢的创建,通过活动或其他原因进行异步任务的坚持的一项活动。在这种情况下有可能调整申请一点点,使用安卓configChanges =定向属性。但是,什么是真正重要的,当你使用这个调整要明白的是,您必须执行保存和正确恢复状态的方法!

For most applications it doesn't really matter if an activity is recreated or not during orientation changes. But sometimes it's more convenient to persist an activity during this process because of slow activity creation, asynchronous tasks performed by an activity or some other reasons. In this case it's possible to tweak an application a little and to use the android:configChanges="orientation" attribute. But what is really important to understand when you use this tweak is that you MUST implement methods for saving and restoring a state properly!

所以,总结一下这个答案,在安卓configChanges 可以让你提高应用程序的性能或使之在某些罕见的情况下表现得本地,但它并没有减少code,你必须编写量。

So to sum up this answer, the android:configChanges can allow you to improve the performance of an application or to make it behave "natively" in some rare cases but it doesn't reduce the amount of code you have to write.

这篇关于强制的Andr​​oid不重绘的方向变化的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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