What Is Activity In Android | Activity In Android Studio | Android Activity Explained In Detail

What is Activity?

An activity is one screen of the Android app. In that way, an Android activity is very similar to window in windows operating system.

To be more specific, the building block of the user interface is the activity. An Android app may contain one or more activities, meaning one or more screens. For e.g. Login, Sign-up & Home screen.

And activity class is a predefined class in Android and every application which has UI must inherit it to create window.

How Activity works?

Activity in Android is a platform or a specifically combination of XML file and Java file It is basically a container which contains design as well as coding stuff.

XML file provides you with the design of your screen.

Java file deals with all the coding stuff like handles what's happening in the design file, getting data which user has inserted into it.

How to create an Activity?

Way 1:

  • Create XML file (add “activity_” before file name. E.g. activity_main.xml).
    • Insert Relative Layout & TextView in xml file.

  • Create java file (add “Activity” after the file name, e.g. MainActivity.java).
    • Override  onCreate(Bundle savedInstanceState) Method.
    • Call setContentView(R.layout.activity_main)

  • Declare activity in the manifest.
    • If you want to make activity as first screen. Write these tags inside activity tag.

Way 2 (Bonus):

Create all activity component automatically using android studio wizard (watch the video for that).

That's all Folks, if you still have any confusion, clear them by commenting below.
And Be Updated with our YouTube Channel.