Android rotation prevents from .post() or UI thread running, related to network call

一笑奈何 提交于 2019-12-13 04:30:56

问题


In my application, I cannot edit any UI elements after a screen orientation is changed.

  1. Defined in FragmentActivity: static Handler uiHandler;

  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!