Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are intent-filters in Android?

In my android app, I wanted to start an activity 'B' from initial activity 'A'. I have created classes for both of these. However when using following code to start 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 in AndroidManifest.xml/manifest/application/activity/intent-filers for activity B then the application worked.

I have two questions:

  • When there are multiple activities entries in AndroidManifest.xml, how does android know which activity to start first?
  • I could not understand intent-filters. Can anyone please 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> 
like image 809
ankitjaininfo Avatar asked Jul 23 '10 19:07

ankitjaininfo


People also ask

What does an Intent filter do?

An intent filter declares the capabilities of its parent component — what an activity or service can do and what types of broadcasts a receiver can handle. It opens the component to receiving intents of the advertised type, while filtering out those that are not meaningful for the component.

What is Intent filter in Android medium?

The intent filter specifies the types of intents that an activity, service, or broadcast receiver can respond. Intent filters are declared in the Android manifest file. Intent filter must contain <action>

What is Intent filter category?

An IntentFilter can match against actions, categories, and data (either via its type, scheme, and/or path) in an Intent. It also includes a "priority" value which is used to order multiple matching filters. IntentFilter objects are often created in XML as part of a package's AndroidManifest.

What does Intent mean in Android?

An intent is to perform an action on the screen. It is mostly used to start activity, send broadcast receiver,start services and send message between two activities. There are two intents available in android as Implicit Intents and Explicit Intents.


1 Answers

An intent filter is an expression in an app's manifest file that specifies the type of intents that the component would like to receive.

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

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); 
like image 165
santoshpatmca Avatar answered Oct 05 '22 22:10

santoshpatmca