marcelpinto / RxFlux

RxFlux is a small framework in order to follow Flux design pattern with RxJava functionalities
Apache License 2.0
326 stars 38 forks source link

Sample app is crash when screen rotated #6

Closed adffice closed 8 years ago

adffice commented 8 years ago

Here is crash log: Caused by: android.os.NetworkOnMainThreadException at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1152) at com.android.org.conscrypt.OpenSSLSocketImpl.close(OpenSSLSocketImpl.java:1010) at com.squareup.okhttp.Connection.closeIfOwnedBy(Connection.java:148) at com.squareup.okhttp.OkHttpClient$1.closeIfOwnedBy(OkHttpClient.java:76) at com.squareup.okhttp.internal.http.HttpConnection.closeIfOwnedBy(HttpConnection.java:137) at com.squareup.okhttp.internal.http.HttpTransport.disconnect(HttpTransport.java:134) at com.squareup.okhttp.internal.http.HttpEngine.disconnect(HttpEngine.java:573) at com.squareup.okhttp.Call.cancel(Call.java:122) at retrofit.OkHttpCall.cancel(OkHttpCall.java:162) at retrofit.RxJavaCallAdapterFactory$CallOnSubscribe$1.call(RxJavaCallAdapterFactory.java:102) at rx.subscriptions.BooleanSubscription.unsubscribe(BooleanSubscription.java:72) at rx.internal.util.SubscriptionList.unsubscribeFromAll(SubscriptionList.java:124) at rx.internal.util.SubscriptionList.unsubscribe(SubscriptionList.java:113) at rx.Subscriber.unsubscribe(Subscriber.java:98) at rx.internal.util.SubscriptionList.unsubscribeFromAll(SubscriptionList.java:124) at rx.internal.util.SubscriptionList.unsubscribe(SubscriptionList.java:113) at rx.Subscriber.unsubscribe(Subscriber.java:98) at rx.internal.util.SubscriptionList.unsubscribeFromAll(SubscriptionList.java:124) at rx.internal.util.SubscriptionList.unsubscribe(SubscriptionList.java:113) at rx.Subscriber.unsubscribe(Subscriber.java:98) at com.hardsoftstudio.rxflux.util.SubscriptionManager.clear(SubscriptionManager.java:59) at com.hardsoftstudio.rxflux.RxFlux.shutdown(RxFlux.java:44) at com.hardsoftstudio.rxflux.RxFlux.onActivityDestroyed(RxFlux.java:104) at android.app.Application.dispatchActivityDestroyed(Application.java:248) at android.app.Activity.onDestroy(Activity.java:1469) at android.support.v4.app.FragmentActivity.onDestroy(FragmentActivity.java:322) at android.support.v7.app.AppCompatActivity.onDestroy(AppCompatActivity.java:161) at android.app.Activity.performDestroy(Activity.java:5417) at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1117) at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3486) at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3517)  at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3717)  at android.app.ActivityThread.access$900(ActivityThread.java:141)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1218)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:136)  at android.app.ActivityThread.main(ActivityThread.java:5113)  at java.lang.reflect.Method.invokeNative(Native Method)  at java.lang.reflect.Method.invoke(Method.java:515)

marcelpinto commented 8 years ago

Thank you to report it. That seams a bug reported at the OkHttp https://github.com/square/okhttp/issues/1592 Since the orientation change force the SubscriptionManager to unsubscribe the task. Then the unsubscription triggers the RxJavaCallAdapterFactory to call cancel. Apparently Android detects that as a async operation in Main thread and throws this exception.

Is being solved but meanwhile there is a work arround

"Calling unsubscribeOn(Schedulers.io()) works around the issue when using rxjava with retrofit for the time being. Found the solution here."

I will fix it soon.

marcelpinto commented 8 years ago

Apparently is fix https://github.com/square/okhttp/pull/2048

I just need to update the version whenever it comes out

adffice commented 8 years ago

Thank you very mach for your kind explanation! I change Retrofit to 2.0.0-beta3(depend on okhttp-3.0.0-RC1) and this issues is solved.

marcelpinto commented 8 years ago

@adffice could you create a PR if you have modified the example?

marcelpinto commented 8 years ago

Thank you @adffice

Fix https://github.com/skimarxall/RxFlux/pull/7