当Android系统调用Intent时,如果没有找到Intent匹配的Activity组件(Component),那么应用将报以下错误:

android.content.ActivityNotFoundException:Unable to find explicit activity class

如果没有使用UncaughtExceptionHandler类来处理全局异常,那么程序将异常退出造成不好的用户体验。为了防止ActivityNotFoundException错误的出现,在启动Activity之前先判断Intent是否存在。

代码如下:

privatestaticbooleanisIntentAvailable(Contextcontex,Intentintent){finalPackageManagerpackageManager=contex.getPackageManager();List<ResolveInfo>list=packageManager.queryIntentActivities(intent,PackageManager.GET_ACTIVITIES);returnlist.size()>0;}


更多相关文章

  1. Android ADV 虚拟卡常见错误Failed to push的解决
  2. Android错误之HAX is not installed on the machine(MAC OS)
  3. android 开发 @override 编译错误 解决办法
  4. Android页面跳转错误解决
  5. Android NDK 开发的栈错误调试
  6. Android启动后遇到错误
  7. android使用ksoap2-android调用webservice时报java.io.EOFExcept
  8. android 监听其它app的错误或者崩溃的方法 (ProcessErrorStateInf

随机推荐

  1. android 动画AnimationSet 和 AnimatorSe
  2. 访问自己创建的Contentprovider 抛异常
  3. android application学习之三
  4. 自己努力要学习啦(android的很多demo 总
  5. Android点击空白处隐藏输入框
  6. Android(安卓)4.2蓝牙介绍 Android(安卓)
  7. 使用Java代码在应用层获取Android系统属
  8. Android中通过其他线程更新主线程UI
  9. Android去除系统自带动画的两种方法
  10. adb shell 命令查看android 应用程序 创