Android :LaunchMode 生命周期
2015-11-03 16:51
323 查看
LaunchMode:
1、standard:在栈顶直接新建读取;
2、singTop:如果栈顶是接下来要读取的,复用栈顶;如果不是就新建;
3、singleTask:删除其以上所有,以其为栈顶读取;
4、singleInstance:调用读取的为栈顶;
<activity
android:name=".ActivityB"
android:LaunchMode="1,2,3,4"
android:label="@string/app_name" >
</activity>
生命周期:
1、standard:在栈顶直接新建读取;
2、singTop:如果栈顶是接下来要读取的,复用栈顶;如果不是就新建;
3、singleTask:删除其以上所有,以其为栈顶读取;
4、singleInstance:调用读取的为栈顶;
<activity
android:name=".ActivityB"
android:LaunchMode="1,2,3,4"
android:label="@string/app_name" >
</activity>
生命周期:
<span style="font-size:18px;">package com.hx.zy.sm; import android.app.Activity; import android.content.Context; 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 final String TGA="MainActivity 生命周期进入"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Log.d(TGA, "onCreate"); final Context context=this; Button button2=(Button) findViewById(R.id.button2); Button button1=(Button) findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent=new Intent(context,ActivityB.class); startActivity(intent); } }); button2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { MainActivity.this.finish(); } }); } @Override protected void onStart() { super.onStart(); Log.d(TGA, "onStart"); } @Override protected void onRestart() { super.onRestart(); Log.d(TGA, "onRestart"); } @Override protected void onResume() { super.onResume(); Log.d(TGA, "onResume"); } @Override protected void onPause() { super.onPause(); Log.d(TGA, "onPause"); } @Override protected void onStop() { super.onStop(); Log.d(TGA, "onStop"); } @Override protected void onDestroy() { super.onDestroy(); Log.d(TGA, "onDestroy"); } }</span>
<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" tools:context="com.hx.zy.sm.MainActivity" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="启动" /> <Button android:id="@+id/button2" android:layout_below="@id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="完成" /> </RelativeLayout>
<span style="font-size:18px;">package com.hx.zy.sm; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class ActivityB extends Activity{ private final String TGA="<span style="font-family: Arial, Helvetica, sans-serif;">ActivityB </span><span style="font-family: Arial, Helvetica, sans-serif;">生命周期“;</span> @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_b); Log.d(TGA, "onCreate"); Button button3 = (Button)findViewById(R.id.button3); button3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Intent intent = new Intent(ActivityB.this,MainActivity.class); //startActivity(intent); ActivityB.this.finish(); } }); } @Override protected void onStart() { super.onStart(); Log.d(TGA, "onStart"); } @Override protected void onRestart() { super.onRestart(); Log.d(TGA, "onRestart"); } @Override protected void onResume() { super.onResume(); Log.d(TGA, "onResume"); } @Override protected void onPause() { super.onPause(); Log.d(TGA, "onPause"); } @Override protected void onStop() { super.onStop(); Log.d(TGA, "onStop"); } @Override protected void onDestroy() { super.onDestroy(); Log.d(TGA, "onDestroy"); } }</span>
<span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/tv" android:layout_width="match_parent" android:layout_height="400dp" android:textSize="25dip" android:text="恭喜你,成功了!" /> <Button android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="启动Main" /> </LinearLayout></span>
相关文章推荐
- Android封装支付宝支付
- Android设计模式源码解析之原型模式
- Android设计模式源码解析之桥接模式
- Android设计模式源码解析之命令模式
- Android设计模式源码解析之责任链模式
- 安卓学习总结第六讲:学习Android.mk的一些语法
- Android设计模式源码解析之迭代器(Iterator)模式
- Android设计模式源码解析之策略模式
- Android混淆命令
- Android 蓝牙
- Android 读写文件操作
- 测试Android耗电量的工具
- Android设计模式源码解析之模板方法模式
- Android设计模式源码解析之外观模式(Facade)
- android学习总结五:继续学习Android.mk
- Android和网页进行js交互的时候,json传参问题
- Android ANR分析及解决方案
- Android中HAL如何向上层提供接口总结
- Android 二维码 生成和识别(附Demo源码)
- Android设计模式源码解析之单例模式