In Android, Application components are necessary building blocks that an Android application consists of. And All components are bound by the application manifest file which contains the description of each component. As I know, if you don’t bind your components in the manifest, you would see they are not working. In this article, we are going to discuss the different types of Android application components.

Anyway, here are the following four main Application Components.

  • Activities
  • Services
  • Broadcast Receivers
  • Content Providers

Activities

android activity

An Activity is just like a page or screen where we do all the designing staffs to handle the user interactions. And it consists of two layers front-end and back-end. XML is used as the front-end and for the back-end, we use Java or Kotlin.

An application could have more than one activity but only one activity is required to make an entry point of the app. That is determined by the manifest. Therefore, that activity is also known as launcher activity.

However, we have discussed the Activity and its life-cycle in details. Read more..

Syntex:

public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

Services

This component is very powerful that can perform long-running operations in the background. And it doesn’t provide a User Interface. For example, you can think of a Music Player app or a Download Manager app. Once you start playing the music or even downloading a file these are basically long-running operations. So after that, even if you close the app how does it continuously playing music in the background? Because of Service.

Syntex:

public class MyDownloadService extends Service {
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }
}

Broadcast Receivers

A broadcast receiver is another crucial component of the application. It can send or receive broadcast messages from the Android system or from other apps automatically. But you need to set an Intent filter for that. For example, when the device starts charging or even when it receives the messages. Our Android system just sends a broadcast on that particular event or whenever anything happened like that.

Syntex:

public class SmsInfoReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        //write your code ..
    }
}

Content Providers

Content Provider allows other apps to manage a shared set of app data that could be stored in a File System, or in an SQ-lite Database, on in Web server. It can be used to create a centralized database management system where the other apps can securely access that database.

Syntex:

public class MyAppDataProvider extends ContentProvider {
    @Override
    public boolean onCreate() {
        return false;
    }

    @Nullable
    @Override
    public Cursor query(@NonNull Uri uri, @Nullable String[] strings, @Nullable String s, @Nullable String[] strings1, @Nullable String s1) {
        return null;
    }

    @Nullable
    @Override
    public String getType(@NonNull Uri uri) {
        return null;
    }

    @Nullable
    @Override
    public Uri insert(@NonNull Uri uri, @Nullable ContentValues contentValues) {
        return null;
    }

    @Override
    public int delete(@NonNull Uri uri, @Nullable String s, @Nullable String[] strings) {
        return 0;
    }

    @Override
    public int update(@NonNull Uri uri, @Nullable ContentValues contentValues, @Nullable String s, @Nullable String[] strings) {
        return 0;
    }
}

Remember: All these four components (Activity, Service, Broadcast Receiver and Content Provider) should be registered or bound in the Manifest. Otherwise components will not work!



Additional Android Application Components

Check out the below table, we have a few additional components.

Component NameDescription
ManifestHolds the configuration of the app. All the components should have to register in the manifest.
FragmentsRepresents a portion of the user interface (UI) in an Activity.
ViewsAny UI elements that are drawn on the screen including buttons, list views, edit texts, etc.
LayoutsView hierarchies that control screen format and appearance of the views.
IntentsMessages wiring components together.
ResourcesExternal elements such as strings, constants, drawable, etc.
NotificationsA notification is a message that displays outside your app’s UI to provide the user with reminders, communication from other people, or other timely information from your app. Users can tap the notification to open your app or take an action directly from the notification.
WidgetsWidgets are an essential aspect of home screen customization. You can imagine them as views of an app’s most important data and functionality that is accessible right from the user’s home screen.

I hope you got all the points of Android AutoCompleteTextView. Anyway if you liked this article then please Subscribe to our Youtube channel for keeping this talk continue. You can also find us on Facebook and Instagram. Thanks for your support.

Translate »