×

Android Introduction


What are android apps ?

Android apps are basically an collection of four Components listed below :-

1) Activity

2) Service

3) Content Provider

4) Broadcast Receiver


1) Activity

Activity is used to create the window that your application uses to draw and receive events from the system. Basically used to draw the window with some user interface through which user interacts with the app. An activity look likes when you read your mails in gmail app that one is considered as one activity, when you compose an email to send someone is considered as another activity for gmail app.

public class MainActivity extends Activity
{
}

2) Service

Consider the situation when you are using facebook app and you are listening music at the same time . So did you faced any issues while running music at the same time when you are using facebook ? No.Right? This is the job of Service to handle the long term processes without blocking any process . Background processing is the main task of Service. Service is implemented by using subclass Service as follows :-

public class MainActivity extends Service
{
}

3) Broadcast Receivers

When screen turns off or on, charging of phone is done, when your music is downloaded from any free music website you receive a notification on status bar etc . These events are originated from the system OS. These system related tasks are performed by Broadcast Receivers.They handle communication between Android OS and applications. Broadcast receivers are implemented by using subclass BroadcastReceiver as follows :-

public class MyReceiver extends BroadcastReceiver {
    public MyReceiver() {
    }
 
    @Override
    public void onReceive(Context context, Intent intent) {
    }
}

4) Content Providers

They handle data and database management related tasks.

public class SampleContentProvider extends  ContentProvider {
   public void onCreate(){}
}