开发者

Suspend orientation change

开发者 https://www.devze.com 2023-02-04 18:16 出处:网络
Documentation says: \"a configuration change (such as a change in screen orientation, language, input devices, etc) will cause your current activity to be destroyed, going through the normal activity

Documentation says: "a configuration change (such as a change in screen orientation, language, input devices, etc) will cause your current activity to be destroyed, going through the normal activity lifecycle process of onPause(), onStop(), and onDestroy()."

I would like to suspend开发者_StackOverflow社区 the orientation change, since it crashes my app if it was done in the middle of a a loop (of reading a file).

How can I do this? Also - looking for some kind of "onOrientationChnage" function :)


First, why not solve the initial problem instead?

90% of the times, the problem that you are facing (when changing orientation) is solved in this question:

Background task, progress dialog, orientation change - is there any 100% working solution?

Read it, correct your code and see if the problems are gone!

If you still want to do it anyway:

Quoting the documentation:

Note: Handling the configuration change yourself can make it much more difficult to use alternative resources, because the system does not automatically apply them for you. This technique should be considered a last resort and is not recommended for most applications.

Still want to do it? Read the following link (where I also found the quotation): http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange

If you rely on android system to use different layouts when you are on portrait/landscape mode, you'll need to start to handle these differences by yourself. If you don't use these features, you may get away without doing nothing fancy :)


If you always want a particular orientation, you can add android:screenOrientation="portrait" (or ="landscape" as an attribute to your tag in the manifest.

At run time, you can call setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

0

精彩评论

暂无评论...
验证码 换一张
取 消