左边按钮是退出,右边是下一页,后面几张是左边箭头是跳到前一张,以前很纯真的用startAcitivty往前跳,跳到第一页的时候退出,后面的Activity还在。
就算launchermode改成singleTask也还是这样,还是要finish()才可以大道Back的效果。
ActivityB.java
package cn.com.bvin.stack; import android.app.Activity; import android.content.Intent; import android.graphics.Color; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.widget.Button; import android.widget.TextView; public class ActivityB extends Activity{ private ViewGroup rootContainer; private Button btNext,btBack; private TextView tvBomt,tvTop; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); getWindow().requestFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); initViews(); } public void initViews(){ rootContainer = (ViewGroup)findViewById(R.id.root); rootContainer.setBackgroundResource(R.drawable.shake_bg3); btNext = (Button)findViewById(R.id.btNext); btBack = (Button)findViewById(R.id.btBack); tvTop = (TextView)findViewById(R.id.tvTop); tvTop.setTextColor(Color.BLACK); tvTop.setText("Hello world,"+getClass().getName()+"!"); tvBomt = (TextView)findViewById(R.id.tvBottom); tvBomt.setText("第三页"); tvBomt.setTextColor(Color.BLACK); rootContainer.setBackgroundResource(R.drawable.shake_bg3); btNext.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub startActivity(new Intent(ActivityB.this,ActivityC.class)); } }); btBack.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub //startActivity(new Intent(ActivityB.this,AcitivtyA.class)); finish(); } }); } }