Gameboy wrote:
> I want to change content of edit text after changing orientaton, but
> seems I get strange problem:
> 
> I use
> mEditor = (EditText) findViewById(R.id.editor); in onCreate(), when
> changing orientation, onCreate() will be invoked again, however seems
> mEditor becomes new one after changing orientaton each time, mEditor
> is not the same original instance before changing orientation, who can
> tell me why and how can I get the original one?

"Why" is because, by default, Android handles a screen rotation by 
destroying and re-creating your activity, so you get the right set of 
resources (e.g., res/layout-land versus res/layout).

"how can I get the original one" is the wrong way of looking at the problem.

Bear in mind that the destroy-and-recreate pattern is used in other 
places in Android besides screen rotations, such as when your 
application must be closed due to low-memory conditions and then later 
re-opened based on user actions. You need to be able to handle this sort 
of scenario as well, and so you do not want to be writing code that 
assumes that, when onCreate() is called on your activity for the 217th 
time, that you can somehow get to the EditText from the 56th onCreate() 
call from three weeks ago.

If, however, you are simply trying to optimize the screen rotation 
scenario, there are some options, with pros and cons. I have a 
three-part blog post series up on AndroidGuys that covers this:

http://androidguys.com/?p=2084
http://androidguys.com/?p=2642
http://androidguys.com/?p=2723

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
_The Busy Coder's Guide to Android Development_ Version 1.4 Published!

--~--~---------~--~----~------------~-------~--~----~
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
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to