rex-weather icon indicating copy to clipboard operation
rex-weather copied to clipboard

does not handle configuration change

Open ber4444 opened this issue 10 years ago • 4 comments

You should add retained fragments (see http://www.androiddesignpatterns.com/2013/04/retaining-objects-across-config-changes.html) or http://developer.android.com/reference/android/content/AsyncTaskLoader.html to retain the REST calls when the activity is restarted on device rotation. Right now, on orientation change, you get an error "sendUserActionEvent() mView == null" and you would notice it much more if you tried it with a bigger dataset than just the current weather.

By the way, because the landscape layout is unusable, you obviously only tested it in portait mode.

ber4444 avatar Sep 22 '14 12:09 ber4444

You're right, I didn't consider configuration changes in this example. I should probably have locked the screen orientation to portrait.

Doing a setRetainInstance(true) in WeatherFragment would be the preferred solution here, since we're using RxJava as a replacement for AsyncTask.

I'll see if I can push a fix out this weekend.

vyshane avatar Sep 23 '14 06:09 vyshane

thanks btw, locking the orientation is called "last resort" at http://developer.android.com/guide/topics/manifest/activity-element.html#config

ber4444 avatar Sep 23 '14 08:09 ber4444

I was not too concerned with the usability of this app to be honest. This is most definitely not a production-ready app. Thanks for caring enough to open an issue though. I'll try to find some time this weekend to fix this.

vyshane avatar Sep 23 '14 09:09 vyshane

@ber4444 locking the screen orientation is not considered a last resort, what is considered a last resort is handling the configurations changes manually by declaring the android:configChanges for your activity, maybe your were thinking about android:screenOrientation still have some caveats but as @vyshane mentioned this is not a production app.

rcgonzalezf avatar Feb 11 '17 16:02 rcgonzalezf