Monday 17 October 2016

Android Activity LifeCycle

Activity means an action speaks to a solitary screen with a UI(User Interface). And its supports of java code .
There are seven different android activity lifecycle are described below .

1) onCreate() :-

Called when the movement is initially made. This is the place you ought to do the greater part of your    ordinary static set up: make sees, tie information to records, and so on.

2) onRestart() : -

Called after your action has been halted, preceding it being begun once more.

3) onStart() : -

Called when the movement is getting to be obvious to the client. Taken after by onResume() if the action goes to the frontal area, or onStop() on the off chance that it gets to be covered up.

4) onResume() : -

Called when the action will begin interfacing with the client. Now your movement is at the highest point of the action stack, with client input going to it.

5) onPause () : -

Called as a major aspect of the movement lifecycle when an action is going away from plain sight, yet has not (yet) been slaughtered.

6) onStop() : -

Called when you are no more extended unmistakable to the client. You will next get either onRestart(), onDestroy(), or nothing, contingent upon later client movement.

7) onDestroy() : -

The last call you get before your action is decimated. This can happen either on the grounds that the movement is completing (somebody called complete() on it, or in light of the fact that the framework is incidentally wrecking this occasion of the action to spare space. You can recognize these two situations with the isFinishing() strategy.

        Diagram or flow chart of Android Activity LifeCycle shown below .

Android Activity LifeCycle
Android Activity LifeCycle Figure

Code for Activity LifeCycle :-

Here in the code we are using "TOAST" (or) we can use "Log.d" content display in the Logcat. If we  want to try Log.d and replace in place of Toast. For 

       Log.id("Activity lifecycle", onCreate()");

package com.kiranapp;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;
import android.view.Menu;

public class MainActivity extends AppCompatActivity {

@Override protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 Toast.makeText(MainActivity.this,"onCreate() Method",Toast.LENGTH_SHORT);
 }

@Override protected void onStart() {
 super.onStart();
 Toast.makeText(MainActivity.this,"onStart() Method",Toast.LENGTH_SHORT);
 }
 
@Override protected void onResume() {
 super.onResume();
 Toast.makeText(MainActivity.this,"onResume() Method",Toast.LENGTH_SHORT);
 }

@Override protected void onPause() {
 super.onPause();
 Toast.makeText(MainActivity.this,"onPause() Method",Toast.LENGTH_SHORT);
 }

@Override protected void onStop() {
 super.onStop();
 Toast.makeText(MainActivity.this,"onStop() Method",Toast.LENGTH_SHORT);
 }

@Override protected void onRestart() {
 super.onRestart();
 Toast.makeText(MainActivity.this,"onRestart() Method",Toast.LENGTH_SHORT);
 }
 
@Override protected void onDestroy() {
 super.onDestroy();
 Toast.makeText(MainActivity.this,"onDestroy() Method",Toast.LENGTH_SHORT);
 }
}

1 comment: