Android Activity Life cycle - LearnHowToCode SarkariResult.com Interview Questions and Answers LearnHowToCodeOnline
Android Activity Life cycle

Android Activity Life cycle


Android Activity Life cycle 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 life cycle method of Activity describes how activity will behave at different states.


Android Activity Life cycle methods
Let's see the 7 life cycle methods of android activity.


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.



                   


UI Widgets

The individual elements of an Android UI are arrenged on screen by means of a variety of Layout Managers derived from the ViewGroup class.
Android components used to create UIs. You all learn how to use layout, Fragments, and Views to create functional UIs for your Activities.
As if a devices can function if it has no style. As if a device can be called stylish that does not function superbly, beauty matters .

Edit Text

An editable text entry box that accepts multiple entry, word awrapping,and hint text.

Text View

A standerd read only text lable that supports multiple display, string formating , and automatic word wraping.

Button

A standard push button.

Check box

A two-state button respresented by a checked or unchecked box.

Radio Button

A two state grouped button. A group of these presents the user with a number of possible options, of which only one can be enabled at a time.

List View

A View Group that creates and manages a vertical list of Views, displaying them as rows within the list. The simplest List View display the toString value of each object in an array, using a Text View for each item.

Chronometer

A Text View extension that implements a simple count-up timer.

Spinner

A composite control that display a Text View and a associated List View that lets you select an item from a list to display in the textbox.

Toggle Button

A two state button that can be used as an alternative to a check box. Its particularly appropriate whare pressing the button will initiate an action as well as changing a state .

Image Button

A push button for which you can specify a customized background image.

Check Box

A two state button represented by a checked or uncheked box

view Flipper

A View Group that lets you define a collection of Views as a horizontal row in which only one View is visible at a time , and in which transitions between visible views can be animated.

Video View

Handles all state management and display Surface configuration for playing video more simply from within your Activity.

QuickContact Badge

Display a badge showing the image icon asssinged to a contact you specify using a phone number, name , email address, or URI.

View Pager

Released as part of the Compatibility Package, the View Page implements a horizontally scrolling set of View similar to the UI used in Google Play and Calender.

Android Activity Lifecycle Example

In this example, we are displaying the content on the logcat.

MainActivity.java

package com.javatportal.activitylifecycle;  
import android.os.Bundle;  
import android.app.Activity;  
import android.util.Log;  
import android.view.Menu;  
public class MainActivity extends Activity {  
    @Override  
    protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.activity_main);  
        Log.d("lifecycle","onCreate invoked");  
    }  
    @Override  
    protected void onStart() {  
        super.onStart();  
         Log.d("lifecycle","onStart invoked");  
    }  
    @Override  
    protected void onResume() {  
        super.onResume();  
         Log.d("lifecycle","onResume invoked");  
    }  
    @Override  
    protected void onPause() {  
        super.onPause();  
         Log.d("lifecycle","onPause invoked");  
    }  
    @Override  
    protected void onStop() {  
        super.onStop();  
         Log.d("lifecycle","onStop invoked");  
    }  
       @Override  
    protected void onRestart() {  
        super.onRestart();  
         Log.d("lifecycle","onRestart invoked");  
    }     
    @Override  
    protected void onDestroy() {  
        super.onDestroy();  
         Log.d("lifecycle","onDestroy invoked");  
    }  
}  

About EasyToCode

I'm Ethan Mariano a software engineer by profession and reader/writter by passion.I have good understanding and knowledge of AngularJS, Database, javascript, web development, digital marketing and exploring other technologies related to Software development.

0 comments:

Featured post

Political Full Forms List

Acronym Full Form MLA Member of Legislative Assembly RSS Really Simple Syndication, Rashtriya Swayamsevak Sangh UNESCO United Nations E...

Powered by Blogger.