0

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 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 :)

OkyDokyman
  • 3,786
  • 7
  • 38
  • 50

2 Answers2

1

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 :)

Community
  • 1
  • 1
Pedro Loureiro
  • 11,436
  • 2
  • 31
  • 37
0

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);

Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
  • Thanks, but I know about this. I 'm asking about suspending change and then allow it. – OkyDokyman Jan 16 '11 at 00:35
  • Found it! I found the solution here: http://stackoverflow.com/questions/4510526/android-is-disabling-landscape-mode-unforgivable This will prevent the crash – OkyDokyman Jan 16 '11 at 00:41
  • @OkyDokyman: Your "solution" is a bad idea in general. Now you will need to manage all resource changes based upon orientation changes. And your original bug is still there and will occur if the user puts their phone in a car dock, for example. Please, just fix the original bug. – CommonsWare Jan 16 '11 at 01:14