Sunday, June 20, 2010

[android-developers] Dubious extra call to OnCreate on orientation change

Hi,

I've been experimenting with orientation change and have seen a
strange behavior (at least to my opinion) when I change the
orientation from landscape to portrait. To make the explanation more
concrete let's consider the following super-simple code:

1. import android.app.Activity;
2. import android.os.Bundle;
3.
4. public class HelloAndroid extends Activity
5. {
6. @Override
7. public void onCreate(Bundle savedInstanceState)
8. {
9. super.onCreate(savedInstanceState);
10. }
11.
12. @Override
13. protected void onDestroy()
14. {
15. super.onDestroy();
16. }
17. }

I put breakpoints at lines 9 and 15 and start the emulator in debug
mode. The application starts and hits the breakpoint at line 9; so far
so good. Then I press Ctrl+F11 to change the orientation from portrait
to landscape. The debugger stops first at line 15 and then line 9.
Everyhting normal so far. I hit once again Ctrl+F11 to change the
orientation from landscape to portrait and some mumbo-jumbo starts
happening. Here is the sequence of function calls I observe:

1.onDestroy()
2.onCreate()
3.onDestroy()
4.onCreate()

I really fail to understand why the platform needs to make the calls
"2.onCreate()" and "3.onDestroy()". Can anyone explain why this is
happening? At least I don't find it convenient because I need to
implement more logic, because the extra calls "2.onCreate()" and
"3.onDestroy()" cause side effects in my case. However, it would be
interesting to know why these extra calls are taking place.

Thank you in advance,

-Ali

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate