Skip to content

Commit

Permalink
Fix NPE in PreviewMediaFragment
Browse files Browse the repository at this point in the history
Fragment can be detached before async task finishes.
Detached fragment has no context and getString() fails with NPE.

Fixes #4412

Signed-off-by: Chris Narkiewicz <hello@ezaquarii.com>
  • Loading branch information
ezaquarii authored and Backportbot committed Oct 2, 2019
1 parent cfe12fe commit 8eb4823
Showing 1 changed file with 4 additions and 3 deletions.
Expand Up @@ -82,6 +82,7 @@
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import androidx.fragment.app.Fragment;


/**
Expand Down Expand Up @@ -552,9 +553,9 @@ protected Uri doInBackground(String... fileId) {

@Override
protected void onPostExecute(Uri uri) {
PreviewMediaFragment previewMediaFragment = previewMediaFragmentWeakReference.get();

if (previewMediaFragment != null) {
final PreviewMediaFragment previewMediaFragment = previewMediaFragmentWeakReference.get();
final Context context = previewMediaFragment != null ? previewMediaFragment.getContext() : null;
if (previewMediaFragment != null && context != null) {
if (uri != null) {
previewMediaFragment.mVideoUri = uri;
previewMediaFragment.mVideoPreview.setVideoURI(uri);
Expand Down

0 comments on commit 8eb4823

Please sign in to comment.