Merge pull request #3349 from ByteHamster/no-crash-after-dispose
Do not crash on undeliverable InterruptedException
This commit is contained in:
commit
46af0e0c36
|
@ -32,7 +32,6 @@ public class ItunesTopListLoader {
|
|||
String lang = Locale.getDefault().getLanguage();
|
||||
OkHttpClient client = AntennapodHttpClient.getHttpClient();
|
||||
String feedString;
|
||||
try {
|
||||
try {
|
||||
feedString = getTopListFeed(client, lang, limit);
|
||||
} catch (IOException e) {
|
||||
|
@ -40,9 +39,6 @@ public class ItunesTopListLoader {
|
|||
}
|
||||
List<PodcastSearchResult> podcasts = parseFeed(feedString);
|
||||
emitter.onSuccess(podcasts);
|
||||
} catch (IOException | JSONException e) {
|
||||
emitter.onError(e);
|
||||
}
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
|
|
|
@ -34,7 +34,7 @@ public class ClientConfig {
|
|||
private static boolean initialized = false;
|
||||
|
||||
public static synchronized void initialize(Context context) {
|
||||
if(initialized) {
|
||||
if (initialized) {
|
||||
return;
|
||||
}
|
||||
PodDBAdapter.init(context);
|
||||
|
@ -42,6 +42,7 @@ public class ClientConfig {
|
|||
PlaybackPreferences.init(context);
|
||||
NetworkUtils.init(context);
|
||||
SleepTimerPreferences.init(context);
|
||||
RxJavaErrorHandlerSetup.setupRxJavaErrorHandler();
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package de.danoeh.antennapod.core.util.exception;
|
||||
|
||||
import android.util.Log;
|
||||
import io.reactivex.exceptions.UndeliverableException;
|
||||
import io.reactivex.plugins.RxJavaPlugins;
|
||||
|
||||
public class RxJavaErrorHandlerSetup {
|
||||
|
||||
private RxJavaErrorHandlerSetup() {
|
||||
|
||||
}
|
||||
|
||||
public static void setupRxJavaErrorHandler() {
|
||||
RxJavaPlugins.setErrorHandler(e -> {
|
||||
if (e instanceof UndeliverableException) {
|
||||
e = e.getCause();
|
||||
}
|
||||
if (e instanceof InterruptedException) {
|
||||
// fine, some blocking code was interrupted by a dispose call
|
||||
Log.d("RxJavaErrorHandler", "Ignored exception: " + Log.getStackTraceString(e));
|
||||
return;
|
||||
}
|
||||
Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), e);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@ import de.danoeh.antennapod.core.preferences.SleepTimerPreferences;
|
|||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.core.storage.PodDBAdapter;
|
||||
import de.danoeh.antennapod.core.util.NetworkUtils;
|
||||
import de.danoeh.antennapod.core.util.exception.RxJavaErrorHandlerSetup;
|
||||
|
||||
/**
|
||||
* Stores callbacks for core classes like Services, DB classes etc. and other configuration variables.
|
||||
|
@ -36,7 +37,7 @@ public class ClientConfig {
|
|||
private static boolean initialized = false;
|
||||
|
||||
public static synchronized void initialize(Context context) {
|
||||
if(initialized) {
|
||||
if (initialized) {
|
||||
return;
|
||||
}
|
||||
PodDBAdapter.init(context);
|
||||
|
@ -45,6 +46,7 @@ public class ClientConfig {
|
|||
NetworkUtils.init(context);
|
||||
CastManager.init(context);
|
||||
SleepTimerPreferences.init(context);
|
||||
RxJavaErrorHandlerSetup.setupRxJavaErrorHandler();
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue