harika
harika

Reputation: 43

Why do we mention activities in manifest?

We specify current activity and start activity for an intent and we call it through the method startService(). So why do we need to mention that activity in manifest again?

Upvotes: 3

Views: 1316

Answers (1)

Mdlc
Mdlc

Reputation: 7288

Indexing (what can your app do?)
I can answer at least part of the why for Activities. The manifest is also where you declare your IntentFilter which is how the system understands what your application does. i.e. should your activity be an illegible choice when the user is trying to take a picture? choose a file? share a piece of text? In addition to that the IntentFilter also tells the Launcher application that you would like to have your activity included in the Applications drawer.

Configuring (what is your main activity?)
There are also several configuration options that you can set on Activities which have to be done in the manifest i.e. SingleTop. Without the declaration in the manifest there would be no place to declare these configurations.

Time Saving (where can the system find your service?)
The manifest file is used by the system to know what kind of components do the application have. Without registering your Activities/Services/Receivers/Content Providers the system would have to scan and parse the whole apk every time someone wants to use a specific component to find it. This would be really slow, that's why there is the AndroidManifest.xml, which is a small file, and it can be parsed fast to find the required component.

Sources: Why do Activities/Services need to be explicitly added to the Android manifest? why acitivies have to be registered in manifest file

Each android application you build will include a file called AndroidManifest.xml which is placed in the root of the project hierarchy. So why is it important? Because it lets you define the structure and metadata of your android application and its components.

http://simpledeveloper.com/android-application-manifest-file/

Upvotes: 5

Related Questions