问题
In my application, I cannot edit any UI elements after a screen orientation is changed.
Defined in FragmentActivity: static Handler uiHandler;
Runned in Fragment in separate thread:
uiHandler.post(new Runnable() { public void run() { chcemhovoritback.setBackgroundColor(Color.MAGENTA); } }
I have runned one post() already in application and I if I run it before orientation changed, no problem.
回答1:
When orientation changes, the activity is recreated. To prevent this from happening, add the following to the <activity>
tag in AndroidManifest.xml
(I wonder why it's not the default behavior):
<activity
...
android:configChanges="orientation|keyboardHidden|screenSize" >
来源:https://stackoverflow.com/questions/18167251/android-rotation-prevents-from-post-or-ui-thread-running-related-to-network