All about Android Activity

 Hello friends hi. This post is regarding all about Android Activity.

In this post you will learn about the following points...

1)- What is an activity?

2)- How is it works?

3)- what is its lifecycle?

4)- How to implement an activity? etc


So let's get start....

So first question is What is an Activity in Android?

The answer is quite simple, An Activity is an android component with a user interface with which a user can interact to it. On the other hands: An activity is a single screen in an application with which a user can interact to perform a task. It is similar to a window or a frame in a desktop application.


An activity comes with their own lifecycle. 

So now the question is what is the lifecycle of an activity?

Life cycle of an activity determines how the activity will be Created, Started, Resumed, Paused, Stopped, Restarted and Destroyed. It consists of several methods.


Here is the pictorial view of Activity lifecycle.









above is the pictorial view of android activity lifecycle.


Now the question is how to implement an activity in our application?

There are two ways to create an activity in our app:-

1)- Automatically using android File structure option.

2)- Manually.


So to create an activity using file structure simply follow the steps below....

Click on App folder --> Kotlin+Java --> right click on package folder (eg: com.ami.techamit

-->File --> New --> Activity --> Select the Activity type (eg: Empty View Activity) --> Give activity 

name without space --> Finish.



                                               Here Is the Video Tutorial




Now to create an activity manually simply follow the steps below....


1)- Click on App folder --> Kotlin+Java --> right click on package folder (eg: com.ami.techamit

--> File --> New --> Kotlin Class / File --> Create a kotlin class file with activity name (eg: TechAmit)

--> Inherit the class with AppCompactActivity() --> Override the onCreate() Method.


2)- Create a new layout xml file in res / layout folder --> In Kotlin class file pass this layout in 

setContentView() method as  ( eg: setContentView(R.layout.activity_tech_amit))


3)- Register the activity in manifest file as...

goto manifest.xml --> use <activity name:=".TechAmit">



                                             Here is the Video Tutorial



                                                ....Done....


Feel free to contact or any suggestion. 

Also subscribe Tech Amit




 



Comments

Popular posts from this blog

All about Fragment in Android

Architectural patterns in Software Engineering