From 6275634b9ef5ec89000349c08b728b5022594676 Mon Sep 17 00:00:00 2001 From: Jeff Chang Date: Tue, 21 Apr 2020 14:25:40 +0800 Subject: [PATCH] Fix NPE when run the testing in IntentPlayground StartActivity with a null intent lead to the NPE when execute the Intent testing. This CL make sure the intent is good before run the testing Bug: 154568140 Test: Manual to run the intent tesing. Change-Id: I8d8bc8e1347ae5f095e01f4a718f2ab936574fcc --- samples/IntentPlayground/res/values/strings.xml | 1 + .../android/intentplayground/BaseActivity.java | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/samples/IntentPlayground/res/values/strings.xml b/samples/IntentPlayground/res/values/strings.xml index a6bdcc4cf..4a3683c4a 100644 --- a/samples/IntentPlayground/res/values/strings.xml +++ b/samples/IntentPlayground/res/values/strings.xml @@ -92,4 +92,5 @@ Select start mode Start activity Start activity for result + Start Intent testing failed diff --git a/samples/IntentPlayground/src/com/example/android/intentplayground/BaseActivity.java b/samples/IntentPlayground/src/com/example/android/intentplayground/BaseActivity.java index 02cad285d..227f517b5 100644 --- a/samples/IntentPlayground/src/com/example/android/intentplayground/BaseActivity.java +++ b/samples/IntentPlayground/src/com/example/android/intentplayground/BaseActivity.java @@ -27,6 +27,8 @@ import android.util.Log; import android.view.Menu; import android.view.MenuItem; +import android.widget.Toast; + import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; @@ -238,8 +240,14 @@ public abstract class BaseActivity extends AppCompatActivity implements } protected void runIntentTests() { - startActivity(getPackageManager() - .getLaunchIntentForPackage("com.example.android.intentplayground.test")); + final Intent intent = getPackageManager() + .getLaunchIntentForPackage("com.example.android.intentplayground.test"); + if (intent != null) { + startActivity(intent); + } else { + Toast.makeText(this, + R.string.launch_testing_activities_failed, Toast.LENGTH_LONG).show(); + } } protected Intent prepareLaunchForward() {