mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Check if activity is still alive before returning results to it
This commit is contained in:
@@ -1,33 +1,36 @@
|
||||
package org.briarproject.android.controller.handler;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.support.annotation.UiThread;
|
||||
|
||||
import org.briarproject.android.fragment.BaseFragment.BaseFragmentListener;
|
||||
|
||||
public abstract class UiResultExceptionHandler<R, E extends Exception>
|
||||
implements ResultExceptionHandler<R, E> {
|
||||
|
||||
private final Activity activity;
|
||||
private final BaseFragmentListener listener;
|
||||
|
||||
public UiResultExceptionHandler(Activity activity) {
|
||||
this.activity = activity;
|
||||
protected UiResultExceptionHandler(BaseFragmentListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResult(final R result) {
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
onResultUi(result);
|
||||
if (!listener.hasBeenDestroyed())
|
||||
onResultUi(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(final E exception) {
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
onExceptionUi(exception);
|
||||
if (!listener.hasBeenDestroyed())
|
||||
onExceptionUi(exception);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,22 +1,24 @@
|
||||
package org.briarproject.android.controller.handler;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.support.annotation.UiThread;
|
||||
|
||||
import org.briarproject.android.fragment.BaseFragment.BaseFragmentListener;
|
||||
|
||||
public abstract class UiResultHandler<R> implements ResultHandler<R> {
|
||||
|
||||
private final Activity activity;
|
||||
private final BaseFragmentListener listener;
|
||||
|
||||
public UiResultHandler(Activity activity) {
|
||||
this.activity = activity;
|
||||
protected UiResultHandler(BaseFragmentListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResult(final R result) {
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
listener.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
onResultUi(result);
|
||||
if (!listener.hasBeenDestroyed())
|
||||
onResultUi(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user