Android中判断Intent是否存在的方法
16lz
2021-01-23
当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;}
更多相关文章
- Android ADV 虚拟卡常见错误Failed to push的解决
- Android错误之HAX is not installed on the machine(MAC OS)
- android 开发 @override 编译错误 解决办法
- Android页面跳转错误解决
- Android NDK 开发的栈错误调试
- Android启动后遇到错误
- android使用ksoap2-android调用webservice时报java.io.EOFExcept
- android 监听其它app的错误或者崩溃的方法 (ProcessErrorStateInf