Merge branch 'run-unless-activity-not-added' into 'master'

Run UI actions only when the activity is added to the fragment.

Closes #1336

See merge request briar/briar!858
This commit is contained in:
akwizgran
2018-07-25 13:33:15 +00:00

View File

@@ -6,6 +6,7 @@ import android.os.Bundle;
import android.support.annotation.CallSuper; import android.support.annotation.CallSuper;
import android.support.annotation.UiThread; import android.support.annotation.UiThread;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.MenuItem; import android.view.MenuItem;
import org.briarproject.bramble.api.db.DbException; import org.briarproject.bramble.api.db.DbException;
@@ -56,8 +57,8 @@ public abstract class BaseFragment extends Fragment
@UiThread @UiThread
protected void finish() { protected void finish() {
if (!isDetached()) FragmentActivity activity = getActivity();
getActivity().supportFinishAfterTransition(); if (activity != null) activity.supportFinishAfterTransition();
} }
public interface BaseFragmentListener { public interface BaseFragmentListener {
@@ -85,7 +86,7 @@ public abstract class BaseFragment extends Fragment
activity.runOnUiThread(() -> { activity.runOnUiThread(() -> {
// Note that we don't have to check if the activity has // Note that we don't have to check if the activity has
// been destroyed as the Fragment has not been detached yet // been destroyed as the Fragment has not been detached yet
if (!isDetached() && !activity.isFinishing()) { if (isAdded() && !activity.isFinishing()) {
r.run(); r.run();
} }
}); });