Ahmad Arslan
Ahmad Arslan

Reputation: 4528

Android: No Activity found to handle Intent error? How it will resolve

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;                                        
               }
           });

Upvotes: 56

Views: 145121

Answers (6)

kokoko
kokoko

Reputation: 3982

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')

Upvotes: 0

Amar Singh
Amar Singh

Reputation: 445

if (intent.resolveActivity(getPackageManager()) == null) {
    Utils.showToast(activity, no_app_available_to_complete_this_task);
} else {
    startActivityForResult(intent, 1);
}

Upvotes: 4

Karthik
Karthik

Reputation: 3529

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>

Upvotes: 60

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 
}

Upvotes: 17

Ahmed Adel Ismail
Ahmed Adel Ismail

Reputation: 2184

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);

Upvotes: 22

jeet
jeet

Reputation: 29199

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.

Upvotes: 1

Related Questions