Name-Ankitkumar Chaudhary Rollno-19 BEIT AAD Assignment-02

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Name-Ankitkumar Chaudhary

Rollno-19 BEIT
AAD Assignment-02

Assignment -02

Q1. Illustrate Android activity life cycle with flowchart.

Ans: Android Activity Lifecycle is controlled by 7 methods of android.app.Activity


class. The android Activity is the subclass of ContextThemeWrapper class.

An activity is the single screen in android. It is like window or frame of Java.

By the help of activity, you can place all your UI components or widgets in a single
screen.

The 7 lifecycle method of Activity describes how activity will behave at different
states.

Method Description

onCreate called when activity is first created.

onStart called when activity is becoming visible to the user.

onResume called when activity will start interacting with the user.

onPause called when activity is not visible to the user.

onStop called when activity is no longer visible to the user.

onRestart called after your activity is stopped, prior to start.

onDestroy called before the activity is destroyed.


Q2. How View and View Group are used for developing Android applications?
Ans:

Android View
The View is a base class for all UI components in android. For example, the EditText class is used
to accept the input from users in android apps, which is a subclass of View.
 
Following are the some of common View subclasses that will be used in android applications.
 

 TextView
 EditText
 Button
 CheckBox
 RadioButton
 ImageButton
 Progress Bar
 Spinner

Like these we have many View subclasses available in android.

Android ViewGroup
The ViewGroup is a subclass of View and it will act as a base class for layouts and layouts
parameters. The ViewGroup will provide an invisible containers to hold
other Views or ViewGroups and to define the layout properties.
 
For example, Linear Layout is the ViewGroup that contains a UI controls like button, textview, etc.
and other layouts also.
 
Following are the commonly used ViewGroup subclasses in android applications.
 

 Linear Layout
 Relative Layout
 Table Layout
 Frame Layout
 Web View
 List View
 Grid View

Both View and ViewGroup subclasses together will play a key role to create a layouts in android


applications.
Q3. What is Intent object? What information Intent object consist of? Explain different types of
intents along with their usage.

Ans: Android Intent is the message that is passed between components such as


activities, content providers, broadcast receivers, services etc.

It is generally used with startActivity() method to invoke activity, broadcast receivers


etc.

The dictionary meaning of intent is intention or purpose. So, it can be described as


the intention to do action.

The LabeledIntent is the subclass of android.content.Intent class.

Android intents are mainly used to:

o Start the service


o Launch an activity
o Display a web page
o Display a list of contacts
o Broadcast a message
o Dial a phone call etc.

Types:

1.Explicit

2.Implicit

Explicit Intent:

 Explicit Intents are used to connect the application internally.


 In Explicit we use the name of component which will be affected by Intent. For
Example: If we know class name then we can navigate the app from One
Activity to another activity using Intent. In the similar way we can start a
service to download a file in background process.

Explicit Intent work internally within an application to perform navigation and data
transfer. The below given code snippet will help you understand the concept of
Explicit Intents
Intent intent = new Intent(getApplicationContext(), SecondActivity.class);
startActivity(intent);

Implicit Intent:

 In Implicit Intents we do need to specify the name of the component. We just


specify the Action which has to be performed and further this action is
handled by the component of another application.
 The basic example of implicit Intent is to open any web page

Intent intentObj = new Intent(Intent.ACTION_VIEW);


intentObj.setData(Uri.parse("https://www.abhiandroid.com"));
startActivity(intentObj);

You might also like