package com.example.dell.alc; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.widget.TextView; public class MainActivity extends ActionBarActivity { public static final String TAG = "Lifecycle_activity"; public static int createCount = 0; public static int startCount = 0; public static int restartCount = 0; public static int resumeCount = 0; public static int pauseCount = 0; public static int stopCount = 0; public static int destroyCount = 0; TextView tv,tv1,tv2,tv3,tv4,tv5,tv6; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); createCount++; Log.d(TAG,"The number of times the Activity created: " + createCount); if(createCount>=1){ TextView tv = (TextView) findViewById(R.id.onCreate); tv.setText("Start count:" + createCount); } setContentView(R.layout.activity_main); } @Override protected void onStart() { super.onStart(); startCount++; Log.d(TAG,"The number of times the Activity started: " + startCount); if(startCount>=1){ TextView tv1 = (TextView) findViewById(R.id.onStart); tv1.setText("Start count:" + startCount); } } @Override protected void onRestart() { super.onRestart(); startCount++; Log.d(TAG,"The number of times the Activity Restarted: " + startCount); if(restartCount>1){ TextView tv2 = (TextView) findViewById(R.id.onRestart); tv2.setText("Restart count:" + restartCount); } } @Override protected void onStop() { super.onStop(); stopCount++; Log.d(TAG,"The number of times the Activity stopped: " + stopCount); if(stopCount>=1){ tv3 = (TextView) findViewById(R.id.onStop); tv3.setText("stop count:" + stopCount); } } @Override protected void onResume() { super.onResume(); resumeCount++; Log.d(TAG,"The number of times the Activity is resumed: " + resumeCount); if(resumeCount>=1){ TextView tv4 = (TextView) findViewById(R.id.onResume); tv4.setText("Resume count:" + resumeCount); } } @Override protected void onPause() { super.onPause(); startCount++; Log.d(TAG,"The number of times the Activity paused: " + pauseCount); if(pauseCount>=0){ TextView tv5 = (TextView) findViewById(R.id.onPause); tv5.setText("pause count:" + pauseCount); } } @Override protected void onDestroy() { super.onDestroy(); destroyCount++; Log.d(TAG, "The number of times the Activity created: " + destroyCount); if (destroyCount >= 0) { TextView tv6 = (TextView) findViewById(R.id.onDestroy); tv6.setText("destroy count:" + destroyCount); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)