What are intent filters in Android?

In my Android app, I wanted to start action “B” from the initial activity “A”. I created classes for both. However, when using the following code to run B, I get a runtime error: application has stopped unexpectedly, try again . Here is my code:

 Intent myIntent = new Intent(this, AddNewActivity.class); startActivity(myIntent); 

When I added a new entry to AndroidManifest.xml/manifest/application/activity/intent-filers for action B, then the application worked.

I have two questions:

  • When there are several activity entries in AndroidManifest.xml , how does the android know for what purpose to start over?
  • I could not understand the filters of intent. Can someone explain.

Here is my partial AndroidManifest.xml

 <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".ListAllActivity" 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=".AddNewActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> 
+45
android android-intent intentfilter
Jul 23 '10 at 19:05
source share
9 answers

When there are several write actions in AndroidManifest.xml, how does android know to start over?

There is no "first". In your case, with your manifest as shown, you will have two icons in your launcher. No matter what the user picks up, it starts.

I could not understand the filters of intent. Can someone explain.

There is quite a lot of documentation on this subject . Please read this and then ask more specific questions.

Also, when you get the message "the application stopped unexpectedly, try again", use adb logcat , DDMS or DDMS perspective in Eclipse to check the Java stack trace associated with the error.

+27
Jul 23 '10 at 20:22
source share

An intent filter is an expression in the application manifest file that indicates the type of intent that the component would like to receive.

When you create an implicit intention, the Android system finds the appropriate component to start by comparing the contents of the intention with the intent filters declared in the manifest file of other applications on the device. If the target matches the intent filter, the system starts this component and delivers an Intent to it.

AndroidManifest.xml

 <activity android:name=".HelloWorld" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.VIEW"/> <category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.BROWSABLE"/> <data android:scheme="http" android:host="androidium.org"/> </intent-filter> </activity> 

Launch HelloWorld

 Intent intent = new Intent (Intent.ACTION_VIEW, Uri.parse("http://androidium.org")); startActivity(intent); 
+49
Feb 06 '14 at 16:33
source share

Change xml first, mark your second action as DEFAULT

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

Now you can initiate this action using the StartActivity method.

+2
Sep 05 '12 at 5:07
source share

When you create an implicit intention, the Android system finds the appropriate component to start by comparing the contents of the intention with the intent filters declared in the manifest file of other applications on the device. If the target matches the target filter, the system starts this component and delivers an Intent to it. If multiple intent filters are compatible, the system displays a dialog box so that the user can choose which application to use.

An intent filter is an expression in the application manifest file that indicates the type of intent that the component would like to receive. For example, by declaring an intent filter for activity, you allow other applications to directly launch your activity with a specific intent. Similarly, if you do not declare any intent filters for activity, then it can only be launched with an explicit intent.

According to: Intents and Intent Filters

+2
Dec 22 '15 at 8:33
source share

Save the first intent filter with the MAIN and LAUNCHER and add another as ANY_NAME and DEFAULT .

Your LAUNCHER will be activity A and DEFAULT will be your activity B.

+1
Feb 28 '11 at 10:52
source share

There cannot be two Lancher AFAIK. Logcat is a useful tool for debugging and checking the status of an application / machine in back. It will automatically switch from one action to another.

+1
Jul 22 2018-12-12T00:
source share

Activity you should have lunch when you open the application mentions it as LAUNCHER in the intent category, and in the rest of the actions, Default is mentioned in the intent category.

For example : - There are 2 actions A and B
Action A is LAUNCHER, so make it as LAUNCHER in the goal category, and B is a child of Activity A, so make it as DEFAULT.

 <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".ListAllActivity" 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=".AddNewActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> </application> 
+1
Oct. 29 '15 at 6:08
source share

target filter is an expression that is present in the manifest of your application that indicates the type of intent that the component should receive. If a component does not have an intent filter, it can get an explicit intent. If the filter component gets both implicit and explicit intent

+1
Mar 23 '16 at 6:42
source share

If possible, try this one instant solution:

 Intent intent =new Intent(getApplicationBaseContext,second_Act.class); StartActivity(intent); 
0
Feb 29 '16 at 4:30
source share



All Articles