下面我分别写了两个xml文件,每个xml中分别放置了两个button,分别为button1和button2,在这里就不写了,我们将要实现的效果是当点击第一个Activity里面的button时切换到第2个Activity,当点击到第2个Activity里的button时,切换到第一个Activity。
如图:
第一个Activity:
view plain
public class ActivityTestActivity extends Activity { /** Called when the activity is first created. */ private final static String TAG="myTag"; boolean flag = true; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button bn = (Button)findViewById(R.id.button1); bn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //创建启动的Activity对应的Intent Intent intent =new Intent(ActivityTestActivity.this,SecondActivity.class); //动intent对应的Activity startActivity(intent); } }); }第二个Activity: