Handling Android implicit activity crashes

134 Views Asked by At

I start the implicit activity in this way:

  Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(miniGameSceneStatus.getPackageName());
        context.startActivity(launchIntent);

If this activity finish I receive a broadcast, but if the activity crashes I can't see anything except it returns to the first activity without any problem.

Is there any way to know what is happening in the second activity?

1

There are 1 best solutions below

2
On

Wrap up your code with null check before to get context and miniGameSceneStatu and your activity will not get crashed.

    if (context != null && miniGameSceneStatus != null) {
        Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(miniGameSceneStatus.getPackageName());

      context.startActivity(launchIntent);
}
  1. Check camera permission before to do any action

    //Camera permission required for Marshmallow version                                
    if (ActivityCompat.checkSelfPermission(getApplicationContext(), 
         Manifest.permission.CAMERA)!= PackageManager.PERMISSION_GRANTED) {
    
    // Callback onRequestPermissionsResult                                     
    ActivityCompat.requestPermissions(ActivityName.this,
                                        new String[ {Manifest.permission.CAMERA}, ACTION_REQUEST_CAMERA);}