• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps android.content.ActivityNotFoundException: No Activity found to handle Intent

c2tarun

Newbie
Hi friends,
I am trying to activate an activity from another activity using implicit intent.

Code fragment of mail activity:

Code:
public void onClick(View view) {
		intent = new Intent(Intent.ACTION_SEND);
		int id = view.getId();
		switch (id) {
		case R.id.addButton: {
			date = reminderDate.getDayOfMonth();
			month = reminderDate.getMonth();
			year = reminderDate.getYear();

			hour = reminderTime.getCurrentHour();
			minute = reminderTime.getCurrentMinute();

			Log.d(TAG, String.format("%s, Date: %s/%s/%s, Time: %s:%s",
					reminderText.getText().toString(), date, month, year, hour,
					minute));
			intent.setType("plain/text");
			intent.putExtra("reminderText", reminderText.getText().toString());
			startActivity(intent);
			break;

		}
		case R.id.cancelButton: {

			Log.d(TAG, "Reminder Cancelled");
			Toast.makeText(this, "Reminder Cancelled", Toast.LENGTH_LONG)
					.show();
			break;

		}
		}
	}

Androidmainfest.xml

Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.reminder"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".QReminderActivity"
            android:label="@string/app_name" >
        </activity>
        <activity android:name=".TimerActivity" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".NotificationActivity" >
            <intent-filter>
                <action android:name="android.intent.action.SEND" />
                <data android:mimeType="plain/text"/>
            </intent-filter>
        </activity>
    </application>

</manifest>

Activity NotificationActivity is in proper place. But on clicking addButton I am getting following exception:

E/AndroidRuntime( 464): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND typ=plain/text (has extras) }
E/AndroidRuntime( 464): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1409)
E/AndroidRuntime( 464): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
E/AndroidRuntime( 464): at android.app.Activity.startActivityForResult(Activity.java:2827)
E/AndroidRuntime( 464): at android.app.Activity.startActivity(Activity.java:2933)
E/AndroidRuntime( 464): at com.reminder.TimerActivity.onClick(TimerActivity.java:60)
E/AndroidRuntime( 464): at android.view.View.performClick(View.java:2485)
E/AndroidRuntime( 464): at android.view.View$PerformClick.run(View.java:9080)
E/AndroidRuntime( 464): at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime( 464): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 464): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 464): at android.app.ActivityThread.main(ActivityThread.java:3683)
E/AndroidRuntime( 464): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 464): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 464): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime( 464): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime( 464): at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 60): Force finishing activity com.reminder/.TimerActivity

Can anyone please help me in finding the issue??
 
I added following line to AndroidManifest.xml and it worked :(

<category android:name="android.intent.category.DEFAULT"/>

I may have a working code but can anyone please explain me why this happened?
 
I added following line to AndroidManifest.xml and it worked :(

<category android:name="android.intent.category.DEFAULT"/>

I may have a working code but can anyone please explain me why this happened?

From the android documentation...

For an intent to pass the category test, every category in the Intent object must match a category in the filter. The filter can list additional categories, but it cannot omit any that are in the intent.
In principle, therefore, an Intent object with no categories should always pass this test, regardless of what's in the filter. That's mostly true. However, with one exception, Android treats all implicit intents passed to startActivity() as if they contained at least one category: "android.intent.category.DEFAULT" (the CATEGORY_DEFAULT constant). Therefore, activities that are willing to receive implicit intents must include "android.intent.category.DEFAULT" in their intent filters. (Filters with "android.intent.action.MAIN" and "android.intent.category.LAUNCHER" settings are the exception. They mark activities that begin new tasks and that are represented on the launcher screen. They can include "android.intent.category.DEFAULT" in the list of categories, but don't need to.) See Using intent matching, later, for more on these filters.)

I don't know if that helps explain it any better or not :)
 
Back
Top Bottom