import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
//当Activity被创建的时候调用的方法
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
System.out.println("oncreate");
}
//当Activity被销毁的时候调用的方法
@Override
protected void onDestroy() {
super.onDestroy();
System.out.println("onDestroy");
}
//Activity界面用户可见的时候调用的方法
@Override
protected void onStart() {
System.out.println("onstart");
super.onStart();
}
//Activity界面用户不再可见的时候调用的方法.
@Override
protected void onStop() {
System.out.println("onstop");
super.onStop();
}
//获取焦点
@Override
protected void onResume() {
System.out.println("onresume");
super.onResume();
}
//失去焦点,暂停
@Override
protected void onPause() {
System.out.println("onpause");
super.onPause();
}
@Override
protected void onRestart() {
System.out.println("onrestart");
super.onRestart();
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
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=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="123dp"
android:text="Button" />
</RelativeLayout>
不日会上传细节描述