Merge pull request #3349 from ByteHamster/no-crash-after-dispose
Do not crash on undeliverable InterruptedException
This commit is contained in:
commit
46af0e0c36
|
@ -33,16 +33,12 @@ public class ItunesTopListLoader {
|
||||||
OkHttpClient client = AntennapodHttpClient.getHttpClient();
|
OkHttpClient client = AntennapodHttpClient.getHttpClient();
|
||||||
String feedString;
|
String feedString;
|
||||||
try {
|
try {
|
||||||
try {
|
feedString = getTopListFeed(client, lang, limit);
|
||||||
feedString = getTopListFeed(client, lang, limit);
|
} catch (IOException e) {
|
||||||
} catch (IOException e) {
|
feedString = getTopListFeed(client, "us", limit);
|
||||||
feedString = getTopListFeed(client, "us", limit);
|
|
||||||
}
|
|
||||||
List<PodcastSearchResult> podcasts = parseFeed(feedString);
|
|
||||||
emitter.onSuccess(podcasts);
|
|
||||||
} catch (IOException | JSONException e) {
|
|
||||||
emitter.onError(e);
|
|
||||||
}
|
}
|
||||||
|
List<PodcastSearchResult> podcasts = parseFeed(feedString);
|
||||||
|
emitter.onSuccess(podcasts);
|
||||||
})
|
})
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread());
|
.observeOn(AndroidSchedulers.mainThread());
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class ClientConfig {
|
||||||
private static boolean initialized = false;
|
private static boolean initialized = false;
|
||||||
|
|
||||||
public static synchronized void initialize(Context context) {
|
public static synchronized void initialize(Context context) {
|
||||||
if(initialized) {
|
if (initialized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PodDBAdapter.init(context);
|
PodDBAdapter.init(context);
|
||||||
|
@ -42,6 +42,7 @@ public class ClientConfig {
|
||||||
PlaybackPreferences.init(context);
|
PlaybackPreferences.init(context);
|
||||||
NetworkUtils.init(context);
|
NetworkUtils.init(context);
|
||||||
SleepTimerPreferences.init(context);
|
SleepTimerPreferences.init(context);
|
||||||
|
RxJavaErrorHandlerSetup.setupRxJavaErrorHandler();
|
||||||
initialized = true;
|
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.preferences.UserPreferences;
|
||||||
import de.danoeh.antennapod.core.storage.PodDBAdapter;
|
import de.danoeh.antennapod.core.storage.PodDBAdapter;
|
||||||
import de.danoeh.antennapod.core.util.NetworkUtils;
|
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.
|
* 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;
|
private static boolean initialized = false;
|
||||||
|
|
||||||
public static synchronized void initialize(Context context) {
|
public static synchronized void initialize(Context context) {
|
||||||
if(initialized) {
|
if (initialized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PodDBAdapter.init(context);
|
PodDBAdapter.init(context);
|
||||||
|
@ -45,6 +46,7 @@ public class ClientConfig {
|
||||||
NetworkUtils.init(context);
|
NetworkUtils.init(context);
|
||||||
CastManager.init(context);
|
CastManager.init(context);
|
||||||
SleepTimerPreferences.init(context);
|
SleepTimerPreferences.init(context);
|
||||||
|
RxJavaErrorHandlerSetup.setupRxJavaErrorHandler();
|
||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue