문제

Im using a MainActivity with a few Fragments.

In the Activity I connect to a server.

I used: android:configChanges="orientation|screenSize" in my Manifest.

So that the Activity keeps the connection on orientation change.

But now I cant use different layout for port/land (Fragments).

Is there a way to force the Fragments to reload on change without the Activity reloading?

도움이 되었습니까?

해결책

You need to move your network operations outside of the Activity/Fragment lifecycle so that your Activity and Fragments can work as intended and you can have long running network operations that aren't interrupted by Activity and Fragment lifecycles. Remember that Activities and Fragments are meant to be dynamic, have narrow concerns, etc. They're not designed for network operations. That's why there's SO much emphasis on using background threads for various things and why there are Services. For example, you could use an IntentService to handle your network operations. Here's an example of how to your Activity would deal with resuming/updating information when configuration changes happen: https://stackoverflow.com/a/4481297/2306657

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top