MainActivity.Java
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(getApplicationContext(),"onCreate Invoked",Toast.LENGTH_SHORT).show();
// Log.d("lifecycle","onCreate invoked");
}
@Override
protected void onStart() {
super.onStart();
// Log.d("lifecycle","onStart invoked");
Toast.makeText(getApplicationContext(),"onStart Invoked",Toast.LENGTH_SHORT).show();
}
@Override
protected void onResume() {
super.onResume();
// Log.d("lifecycle","onResume invoked");
Toast.makeText(getApplicationContext(),"onResume Invoked",Toast.LENGTH_SHORT).show();
}
@Override
protected void onPause() {
super.onPause();
Toast.makeText(getApplicationContext(),"onPause Invoked",Toast.LENGTH_SHORT).show();
//Log.d("lifecycle","onPause invoked");
}
@Override
protected void onStop() {
super.onStop();
// Log.d("lifecycle","onStop invoked");
Toast.makeText(getApplicationContext(),"onStop Invoked",Toast.LENGTH_SHORT).show();
}
@Override
protected void onRestart() {
super.onRestart();
//Log.d("lifecycle","onRestart invoked");
Toast.makeText(getApplicationContext(),"onRestart Invoked",Toast.LENGTH_SHORT).show();
}
@Override
protected void onDestroy() {
super.onDestroy();
Toast.makeText(getApplicationContext(),"onDestroy Invoked",Toast.LENGTH_SHORT).show();
// Log.d("lifecycle","onDestroy invoked");
}
}
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"
android:orientation="horizontal"
android:gravity="center"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:id="@+id/txtdisp"
android:textColor="@color/Black"
android:textSize="20dp"
android:gravity="center"/>
</LinearLayout>
AndroidManifest.xml
<activity
android:name=".MainActivity"
android:label="MainActivity"
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>



