Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start Activity with action, but no category

I am trying to start an activity defined in another apk, in its AndroidManifest.xml, it defines an activity and with an action, but no category defined.

The format is like

<activity name="...">
    <intent-filter>
        <action android:name="action name">
    <intent-filter>
</activity>

My code is following

Intent i = new Intent("action name");
startActivity(i);

However my apk crashed with uncaught ActivityNotFound exception, the logs read No Activity found to handle intent ... "

Any thoughts?

Thanx a lot.

like image 982
Jimmy Avatar asked Dec 21 '11 00:12

Jimmy


People also ask

What is the difference between categories and actions?

action : Declares the intent action accepted, in the name attribute. The value must be the literal string value of an action, not the class constant. category: Declares the intent category accepted, in the name attribute. The value must be the literal string value of an action, not the class constant.

How do you start a activity from a non activity class?

public Context call mcontext;<br> // ..... <br> Intent intent = new Intent(call mcontext, AboutActivity. class);<br> call mcontext. startActivity(intent);

How do I start an activity in another application?

If both application have the same signature (meaning that both APPS are yours and signed with the same key), you can call your other app activity as follows: Intent LaunchIntent = getActivity(). getPackageManager(). getLaunchIntentForPackage(CALC_PACKAGE_NAME); startActivity(LaunchIntent);

Which type of intent should we use to start an activity?

To start an activity, use the method startActivity(intent) . This method is defined on the Context object which Activity extends. The following code demonstrates how you can start another activity via an intent. # Start the activity connect to the # specified class Intent i = new Intent(this, ActivityTwo.


2 Answers

Looking at the Intent documentation, it says Note also the DEFAULT category supplied here: this is required for the Context.startActivity method to resolve your activity when its component name is not explicitly specified. If the activity's IntentFilter definition does not include that category then you can't start it with startActivity. Try using the setClassName method, and pass it the package class and the activity class you're trying to launch.

like image 121
Femi Avatar answered Sep 28 '22 06:09

Femi


you cannot have empty category when you use startActivity(...).

add a default category and this will do the job:

<intent-filter>
    <action android:name="action name" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
like image 44
Mark Avatar answered Sep 28 '22 05:09

Mark