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
This commit is contained in:
Jeff Chang
2020-04-21 14:25:40 +08:00
parent d9dc576a2a
commit 6275634b9e
2 changed files with 11 additions and 2 deletions

View File

@@ -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() {