Android App Development With AndroidCource: activity structure
Showing posts with label activity structure. Show all posts
Showing posts with label activity structure. Show all posts

Monday, 21 August 2017

Activity Life Cycle Example In Android

LifeCycleActivity.xml
        <?xml version="1.0" encoding="utf-8"?>
         <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:id="@+id/activity_life_cycle"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingBottom="@dimen/activity_vertical_margin"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:paddingTop="@dimen/activity_vertical_margin"
                tools:context="com.example.bhaumik.practicalapp.LifeCycleActivity">

                    <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:textSize="25dp"
                            android:textColor="#000"
                            android:text="Activity LifeCycle Method"
                            android:layout_centerInParent="true"
                    />

            </RelativeLayout>
LifecycleActivity.java
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

public class LifeCycleActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_life_cycle);

        Log.d("Activity : ","onCreate() called");
        ToastMsg.ShowToast(LifeCycleActivity.this,"onCreate() called");
    }

    @Override
    protected void onStart() {
        super.onStart();

        Log.d("Activity : ","onStart() called");
        ToastMsg.ShowToast(LifeCycleActivity.this,"onStart() called");
    }

    @Override
    protected void onPause() {
        super.onPause();

        Log.d("Activity : ","onPause() called");
        ToastMsg.ShowToast(LifeCycleActivity.this,"onPause() called");
    }

    @Override
    protected void onStop() {
        super.onStop();

        Log.d("Activity : ","onStop() called");
        ToastMsg.ShowToast(LifeCycleActivity.this,"onStop() called");
    }

    @Override
    protected void onResume() {
        super.onResume();

        Log.d("Activity : ","onResume() called");
        ToastMsg.ShowToast(LifeCycleActivity.this,"onResume() called");
    }

    @Override
    protected void onRestart() {
        super.onRestart();

        Log.d("Activity : ","onRestart() called");
        ToastMsg.ShowToast(LifeCycleActivity.this,"onRestart() called");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        Log.d("Activity : ","onDestroy() called");
        ToastMsg.ShowToast(LifeCycleActivity.this,"onDestroy() called");
    }
}

Ads