The Android#startActivity(Intent) is specified to throw android.content.ActivityNotFoundException
if there was no Activity found to run the given Intent.
I therefore have code like
try {
// Try to start activity provided by external app:
startActivity(intent);
} catch (ActivityNotFoundException e) {
// [...] Inform user about external app needed
// for this functionality to work.
}
which catches ActivityNotFoundException
to handle the case where the external app is not installed.
However, from the Crashes & ANRs section of the Google Play Developer Console I'm starting to get crashes as IllegalArgumentException: Unknown component com.example.package/com.example.package.Activity
. Should code invoking startActivity()
be ready to handle that exception as well? Is this a framework bug (or documentation error)?
This exception generally arises when you haven't declared it in your manifest file. So, try doing it Somewhere inside your application tag do this
<activity
android:name="Your_Activity_Name"
android:theme="Whatever your theme is"
</activity>
If its any other issue please let me know.
You can use this code to check it. This is the better approach then handling exception
List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
if (list.size() > 0)
{
// start your activity
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.