Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implicit Intent not being called

I am trying to use Implicit intent to launch an activity within the same application and for an activity of another application(my other application, not the native one), but couldn't succeed in any of the cases.

Here is my sample code for the first part (i.e. to launch an activity within the same application):

Inside Activity TESTActivity

Intent intent = new Intent();
intent.setAction("com.myapp.game.myimplicit_action");
startActivity(intent);

and here is my manifest file declaration for some activity say 'ImplicitActivity' with the same action:

<activity
   android:name=".TESTActivity"
   android:label="@string/app_name" >
   <intent-filter>
   <action android:name="android.intent.action.MAIN" />
   <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>
</activity>

<activity  android:name=".ImplicitActivity">
   <intent-filter>
   <action android:name="com.myapp.test.myimplicit_action" />
   </intent-filter>
</activity>

Both the activities TESTActivity and ImplicitActivity are in the same application under same package. Still my ImplicitActivity activity is not getting called.

like image 605
AndoAiron Avatar asked Apr 24 '12 10:04

AndoAiron


People also ask

What is not specified by the implicit intent?

Implicit Intent doesn't specifiy the component. In such case, intent provides information of available components provided by the system that is to be invoked.

What is required when starting an implicit intent?

In android, Implicit Intents won't specify any name of the component to start instead, it declare an action to perform and it allows a component from other apps to handle it. For example, by using implicit intents we can request another app to show the location details of the user or etc.

What will happen if there is any action in an implicit?

What will happen if there is any action in an implicit? Options 1) Nothing will happen, but it will not launch any new screen. 2) Nothing will happen, some how how it launches target component 3) It will throw run time exception - activityNotFoundException, and crashes if it is handled properly. 4) Compile time error.

What do you mean by implicit intent?

This intent specifies an action that can be invoked by any app on the device which enables us to perform an action. It does not have exact knowledge about the landing component. It can open another app or its own app's component and many other options exist.


1 Answers

I have figured out the problem. Posting the answer for the others facing the same problem.

We need to add Default Category in order to make Implicit intents work. So here is the correct manifest entry for the same activity :

<activity
   android:name=".TESTActivity"
   android:label="@string/app_name" >
   <intent-filter>
   <action android:name="android.intent.action.MAIN" />
   <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>
</activity>

<activity  android:name=".ImplicitActivity">
   <intent-filter>
   <action android:name="com.myapp.test.myimplicit_action" />
   <category android:name="android.intent.category.DEFAULT" />
   </intent-filter>
</activity>
like image 137
AndoAiron Avatar answered Sep 28 '22 15:09

AndoAiron