56

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;                                        
               }
           });
NagarjunaReddy
  • 8,621
  • 10
  • 63
  • 98
Ahmad Arslan
  • 4,498
  • 8
  • 38
  • 59
  • 1
    have you registered the intent filter (`"com.scytec.datamobile.vd.gui.android.AppPreferenceActivity"`) for the activity in manifiest? – Karthik Feb 06 '12 at 08:42
  • 1
    No . how it can ? please write proper intent ? i mean to say code – Ahmad Arslan Feb 06 '12 at 08:43
  • 1
    post your manifest file here, (with the entry corresponding to activity - AppPreferenceActivity). then we can help you with right code. – Karthik Feb 06 '12 at 08:46
  • public class AppPreferenceActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); } } – Ahmad Arslan Feb 06 '12 at 08:59
  • 1
    the manifest does not have AppPreferenceActivity? you can edit your question to post the manifest file content. Don't use comments section. – Karthik Feb 06 '12 at 09:12

6 Answers6

59

Add the below to your manifest:

  <activity   android:name=".AppPreferenceActivity" android:label="@string/app_name">  
     <intent-filter> 
       <action android:name="com.scytec.datamobile.vd.gui.android.AppPreferenceActivity" />  
       <category android:name="android.intent.category.DEFAULT" />  
     </intent-filter>   
  </activity>
Karthik
  • 3,509
  • 1
  • 20
  • 26
21

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);
Ahmed Adel Ismail
  • 2,168
  • 16
  • 23
17

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 
}
  • 28
    I disagree. What you should be doing is to check first if the intent can be handled by any activity ` if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } ` – Mark Pazon Mar 15 '18 at 07:22
  • 3
    @MarkPazon this works in 99% of the cases but if you have an activity handling a custom scheme, then you could run into a crash if the user is running an old version of the app without the new scheme in the manifest. – Codeversed Aug 02 '19 at 14:08
4
if (intent.resolveActivity(getPackageManager()) == null) {
    Utils.showToast(activity, no_app_available_to_complete_this_task);
} else {
    startActivityForResult(intent, 1);
}
Maxim Mazurok
  • 3,856
  • 2
  • 22
  • 37
Amar Singh
  • 435
  • 5
  • 9
  • Can you explain why this would work for the original question? – mjuarez Dec 18 '19 at 22:08
  • 1
    this is example to check that activity available or not with related intent whatever you user as your requirment startActivity() or startActivityForResult() resolveActivity check that any activity/package to handle this intent exist or not – Amar Singh Dec 19 '19 at 16:53
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.

jeet
  • 29,001
  • 6
  • 52
  • 53
  • he constructor Intent(new Preference.OnPreferenceClickListener(){}, Class) is undefined – Ahmad Arslan Feb 06 '12 at 09:01
  • use your first activity name instead of ActivityName instead of this only, as first parameter should be instance of an Activity. – jeet Feb 06 '12 at 09:22
0

if you handle the activity that couldnt find at another module make sure that you have added below line on your build.gradle file:

implementation project(':YOUR-MODULE-ROOT')
aligur
  • 3,387
  • 3
  • 34
  • 51