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.
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.
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? 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.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With