在MainActivity.java程序中调用SecondActivity,而不用把MainActivity关闭。
MainActivity.java 文件------
...
myButton1 = (Button) findViewById(R.id.button1);
myButton1.setOnClickListener(new View.OnClickListener() {public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(MainActivity.this, SecondActivity.class);
startActivity(intent);
}
});
...
SecondActivity.java文件-------
...
Button myButton2 = (Button) findViewById(R.id.button2);
myButton2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
SecondActivity.this.finish();
}
});
...
AndroidManifest.xml文件:
...
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SecondActivity"
android:label="@string/title_activity_second" >
</activity>
...