如何处理好ActivityNotFoundException? [英] How to handle the ActivityNotFoundException?

查看:164
本文介绍了如何处理好ActivityNotFoundException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我需要使用startActivity看到文件的内容,或者使用默认的应用程序打开某些文件,但有时Android系统可能无法安装所需要的应用程序。

In my app , I need to use startActivity to see the content of the file , or use the default application to open the certain file , but sometimes the android system may not install the application which is needed .

我的问题是如何处理这个异常。我想敬酒,而不是FC ..

My question is how to handle this exception . I want a toast , not FC..

什么建议? THX

推荐答案

只需简单的添加在你的清单文件的活动。

喜欢,

<activity android:name=".ActivityName"
                  android:label="@string/app_name">
        </activity>

编辑:

现在赶上 ActivityNOtFoundException 把你的code中,

Now to catch the ActivityNOtFoundException put your code in,

try {

  // Your startActivity code wich throws exception  
} catch (ActivityNotFoundException activityNotFound) {

    // Now, You can catch the exception here and do what you want
}

请注意:要小心,当你抓住这个 ActivityNotFound 例外,但你不能修改清单文件运行时,意味着一旦你遇到的异常,如果你想补充一点,在运行时该活动标签那么你就不能。

Note: Be careful when you catch this ActivityNotFound Exception but you can't modified manifest file to run time, means once you encountered the exception and if you want to add that this activity tag at runtime then you can't.

这篇关于如何处理好ActivityNotFoundException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆