From 7f0c849fb06f49d0e591786d37ab6d27efe23b4d Mon Sep 17 00:00:00 2001 From: Albert Vaca Cintora Date: Mon, 25 Nov 2019 14:32:27 +0100 Subject: [PATCH] Fix NPE on plugin in onActivityResult --- .../Plugins/PhotoPlugin/PhotoActivity.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/org/kde/kdeconnect/Plugins/PhotoPlugin/PhotoActivity.java b/src/org/kde/kdeconnect/Plugins/PhotoPlugin/PhotoActivity.java index aeb76e1b..92e8fcbf 100644 --- a/src/org/kde/kdeconnect/Plugins/PhotoPlugin/PhotoActivity.java +++ b/src/org/kde/kdeconnect/Plugins/PhotoPlugin/PhotoActivity.java @@ -19,14 +19,11 @@ import androidx.core.content.FileProvider; public class PhotoActivity extends AppCompatActivity { private Uri photoURI; - private PhotoPlugin plugin; @Override protected void onStart() { super.onStart(); - BackgroundService.RunWithPlugin(this, getIntent().getStringExtra("deviceId"), PhotoPlugin.class, plugin -> this.plugin = plugin); - Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(getPackageManager()) != null) { File photoFile = null; @@ -61,12 +58,13 @@ public class PhotoActivity extends AppCompatActivity { @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); - - if (resultCode == -1) { - plugin.sendPhoto(photoURI); - } else { - plugin.sendCancel(); - } + BackgroundService.RunWithPlugin(this, getIntent().getStringExtra("deviceId"), PhotoPlugin.class, plugin -> { + if (resultCode == -1) { + plugin.sendPhoto(photoURI); + } else { + plugin.sendCancel(); + } + }); finish(); } }