开发者

Orientation change issue in Android

I'm starting a thread from activity which is downloading a file. But in between, if it changes the orientation, then it st开发者_开发技巧arts the new activity. This is not the right way to behave, rather it should continue to download from the state where it was before the orientation change.


You can instruct the system to ignore the orientation changes by including the following code in your manifest file:

<activity android:name="SomeActivity" 
android:configChanges="keyboardHidden|orientation"> 

By declaring a configuration with this attribute will prevent the activity from being restarted. Instead, the activity remains running and its onConfigurationChanged() method is called.
you can override onConfigurationChanged() method in your activity too.

For more details see this link and link2


This is done with the android:configChanges attribute in its manifest. For any types of configuration changes you say that you handle there, you will receive a call to your current activity's onConfigurationChanged(Configuration) method instead of being restarted. If a configuration change involves any that you do not handle, however, the activity will still be restarted and onConfigurationChanged(Configuration) will not be called.

Taken from the Activity class documentation.

Alex


If you start a new thread manually or use something like AsyncTask, the file will continue to download automatically; there's nothing special you need to do. Just don't recreate another thread during onCreate().

The trick is that when the old thread finishes, you need to talk to the new post-rotation activity or start a new activity.

Also, you should work on your accept rate.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜