intent.resolveActivity != null but launching the intent throws an ActivityNotFound exception

后端 未结 2 1195
情深已故
情深已故 2020-12-09 16:28

I post this question here for educational purposes, since I couldn\'t find answers anywhere and eventually found the root cause the old way, i.e. by myself.

Here\'s

2条回答
  •  一个人的身影
    2020-12-09 16:39

    ActivityNotFound exception is thrown when a call to startActivity(Intent) or one of its variants fails because an Activity can not be found to execute the given Intent. For example, if you’re trying to send an email, but there is no app on your device that could process ACTION_SEND intent action, ActivityNotFound will be thrown.

    A way to avoid the exception is to do the following:

    final ComponentName componentName = intent.resolveActivity(pm);
    if (componentName != null) {
      try {
        context.startActivity(intent);    
      } catch (ActivityNotFoundException ex) {
        // Notify the user?
      }
    }
    

提交回复
热议问题