The following two tabs change content below.
Hi, I have written and developed this site to share my experience and ideas with other colleagues. I also started to prepare interview questions and answers for job seekers. I hope it will help you a lot.

An Activity is an application component that provides a screen with which users can interact in order to do something, such as dial the phone, take a photo, send an email, or view a map.

Note: Activity is not compulsory to have in the application because if don’t want to show any user view means only want to do a background operation then activity is not required you can achieve that with Broadcast Receiver and Service.

An application usually consists of multiple activities that are loosely bound to each other. Typically, one activity in an application is specified as the “main” activity, which is presented to the user when launching the application for the first time. Every activity has a view/layout to show the frontend design to customer.

Just a simple example for basic explanation:
1. Open android studio (IDE) and create a new project. Project structure will be look like :


2. In the right side view you can see we have created a by extending the Activity class. In below example onCreate() is a callback function for full activity lifecycle you can follow this link

public class MainActivity extends Activity {

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

3. As I mention every Activity has a layout to show front end view to customer/user. In activity we are integrating the layout using :


If we are not calling this method then UI layout will not be integrated with activity and activity will be without UI means blank activity.

Layout file will be .xml file and will be look like:


From the bottom after click on design tab you can see the design of layout.

4. Once you are ready to run the application make sure you have done the new activity entry in “AndroidMenifest.xml”. If you are creating activity from android studio wizard then android studio will do this entry automatically for you.
View of AndroidMenifest.xml file is given below:


5. Now basic activity application is done for test click on run button and see the result



For activity life cycle 

1,556 total views, 1 views today

One thought on “What is Activity? simple example of activity in android application?”

Leave a Reply

Your email address will not be published. Required fields are marked *