0

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?

Péter Kovács
  • 184
  • 1
  • 1
  • 17
  • You could use `startActivityForResult()` if the `Activity` you are calling can return a result instead of a broadcast. In this way you can determine if it was successful or not. – David Wasser Nov 07 '18 at 14:56

1 Answers1

0

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);}
    
Haider Ali
  • 122
  • 7
  • The problem is not about launching a new activity. The problem is when the launched activity crashes, and I want to know why. For example, when you start the camera app for taking a picture, but it crashes before the photo shot. – Péter Kovács Nov 06 '18 at 11:28
  • @PéterKovács Please share your log cat with me so I can help you out. – Haider Ali Nov 06 '18 at 11:42