public void onCreate(Bundle savedInstanceState) ; public void onDestroy(); public void onPause(); public void onRestart(); public void onResume(); public void onStart(); public void onStop();
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">Hello World, MainActivity!</string> <string name="app_name">Activity生命周期</string> <string name="other">另外一个Activity</string> <string name="start">启动另一个Activity</string> <string name="stop">结束当前Activity</string> </resources>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/start" android:id="@+id/start" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/stop" android:id="@+id/stop" /> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.shun.android"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".OtherActivity"
android:label="@string/other">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
package com.shun.android;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
private static final String TAG = "MainActivity";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.i(TAG,"onCreate");
Button start = (Button)findViewById(R.id.start);
start.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,OtherActivity.class);
startActivity(intent);
MainActivity.this.finish();
}
});
Button stop = (Button)findViewById(R.id.stop);
stop.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
MainActivity.this.finish();
}
});
}
protected void onDestroy(){
Log.i(TAG,"onDestroy");
super.onDestroy();
}
protected void onPause(){
Log.i(TAG,"onPause");
super.onPause();
}
protected void onRestart(){
Log.i(TAG,"onRestart");
super.onRestart();
}
protected void onResume(){
Log.i(TAG,"onResume");
super.onResume();
}
protected void onStart(){
Log.i(TAG,"onStart");
super.onStart();
}
protected void onStop(){
Log.i(TAG,"onStop");
super.onStop();
}
}
package com.shun.android;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class OtherActivity extends Activity{
private static final String TAG = "OtherActivity";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.i(TAG,"onCreate");
Button start = (Button)findViewById(R.id.start);
start.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(OtherActivity.this,MainActivity.class);
startActivity(intent);
OtherActivity.this.finish();
}
});
Button stop = (Button)findViewById(R.id.stop);
stop.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
OtherActivity.this.finish();
}
});
}
protected void onDestroy(){
Log.i(TAG,"onDestroy");
super.onDestroy();
}
protected void onPause(){
Log.i(TAG,"onPause");
super.onPause();
}
protected void onRestart(){
Log.i(TAG,"onRestart");
super.onRestart();
}
protected void onResume(){
Log.i(TAG,"onResume");
super.onResume();
}
protected void onStart(){
Log.i(TAG,"onStart");
super.onStart();
}
protected void onStop(){
Log.i(TAG,"onStop");
super.onStop();
}
}
start.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
MainActivity.this.finish();
Intent intent = new Intent(MainActivity.this,OtherActivity.class);
startActivity(intent);
}
});
Button start = (Button)findViewById(R.id.start);
start.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
OtherActivity.this.finish();
}
});
MainActivity如下:
Button start = (Button)findViewById(R.id.start);
start.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,OtherActivity.class);
startActivity(intent);
}
});
<activity android:name=".OtherActivity"
android:label="@string/other"
android:theme="@android:style/Theme.Dialog">
</activity>
Button start = (Button)findViewById(R.id.start);
start.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,OtherActivity.class);
startActivity(intent);
}
});
Button start = (Button)findViewById(R.id.start);
start.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
OtherActivity.this.finish();
}
});
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有