info@thistimebd.com

Sunday 24th of November 09:04:58am

activity life cycle

package com.tis.web.activitylifecycle;


import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.widget.Toast;


public class MainActivity extends AppCompatActivity {


    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        Toast.makeText(MainActivity.this,"onCreate",Toast.LENGTH_SHORT).show();

    }


    @Override

    protected void onStart() {

        super.onStart();

        Toast.makeText(MainActivity.this,"onStart",Toast.LENGTH_SHORT).show();

    }


    @Override

    protected void onResume() {

        super.onResume();

        Toast.makeText(MainActivity.this,"onResume",Toast.LENGTH_SHORT).show();

    }


    @Override

    protected void onPause() {

        super.onPause();

        Toast.makeText(MainActivity.this,"onPause",Toast.LENGTH_SHORT).show();

    }


    @Override

    protected void onStop() {

        super.onStop();

        Toast.makeText(MainActivity.this,"onStop",Toast.LENGTH_SHORT).show();

    }


    @Override

    protected void onRestart() {

        super.onRestart();

        Toast.makeText(MainActivity.this,"onRestart",Toast.LENGTH_SHORT).show();

    }


    @Override

    protected void onDestroy() {

        super.onDestroy();

        Toast.makeText(MainActivity.this,"onDestroy",Toast.LENGTH_SHORT).show();

    }

}


activity_main.xml



<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    tools:context="com.tis.web.activitylifecycle.MainActivity">




    <Button

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="Login"

        android:textStyle="bold"

        android:textSize="20sp"

        />


</LinearLayout>