代码如下:
package cn.asarea.app.testandroid;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
public class MainActivity extends Activity {
private static final String TAG = "test andriod";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.e(TAG, Thread.currentThread().getStackTrace()[2].getMethodName());
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
// StackTraceElement stackTraceElements[] = Thread.currentThread().getStackTrace();
// for (StackTraceElement stackTraceElement : stackTraceElements) {
// Log.e(TAG, stackTraceElement.getClassName() + ":" + stackTraceElement.getMethodName());
// }
Log.e(TAG, Thread.currentThread().getStackTrace()[2].getMethodName());
}
@Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();
Log.e(TAG, Thread.currentThread().getStackTrace()[2].getMethodName());
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
Log.e(TAG, Thread.currentThread().getStackTrace()[2].getMethodName());
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
Log.e(TAG, Thread.currentThread().getStackTrace()[2].getMethodName());
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
Log.e(TAG, Thread.currentThread().getStackTrace()[2].getMethodName());
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
Log.e(TAG, Thread.currentThread().getStackTrace()[2].getMethodName());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}