No Activity found to handle Intent error? How it will resolve.
Preference customPref = (Preference) findPreference("DataEntryScreen");
customPref
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
Intent i = new Intent("com.scytec.datamobile.vd.gui.android.AppPreferenceActivity");
startActivity(i);
return true;
}
});
This question is related to
android
android-activity
android-intent
preferences
onitemclicklistener
in my case, i was sure that the action is correct, but i was passing wrong URL, i passed the website link without the http:// in it's beginning, so it caused the same issue, here is my manifest (part of it)
<activity
android:name=".MyBrowser"
android:label="MyBrowser Activity" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="com.dsociety.activities.MyBrowser" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
</intent-filter>
</activity>
when i code the following, the same Exception is thrown at run time :
Intent intent = new Intent();
intent.setAction("com.dsociety.activities.MyBrowser");
intent.setData(Uri.parse("www.google.com")); // should be http://www.google.com
startActivity(intent);
if (intent.resolveActivity(getPackageManager()) == null) {
Utils.showToast(activity, no_app_available_to_complete_this_task);
} else {
startActivityForResult(intent, 1);
}
Intent intent=new Intent(String) is defined for parameter task, whereas you are passing parameter componentname into this, use instead:
Intent i = new Intent(Settings.this, com.scytec.datamobile.vd.gui.android.AppPreferenceActivity.class);
startActivity(i);
In this statement replace ActivityName by Name of Class of Activity, this code resides in.
Generally to avoid this kind of exceptions, you will need to surround your code by try and catch like this
try{
// your intent here
} catch (ActivityNotFoundException e) {
// show message to user
}
Source: Stackoverflow.com