假设我有四个班级。每个班级都有一个按钮可以从一个页面切换到另一个页面,它工作正常。但现在我试图通过单击最后一页的按钮来关闭所有活动。我试过了也是,但它只是关闭了最后一页。如何实现这个概念?
请找到我的代码以供参考
Xit_demoActivity.java
public class Xit_demoActivity extends Activity {
/** Called when the activity is first created. */
Button btn1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn1 = (Button)findViewById(R.id.button_1);
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent myIntent = new Intent(v.getContext(), Class1.class);
startActivity(myIntent);
}
});
Class1.java
public class Class1 extends Activity
{
Button btn1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
btn1 = (Button)findViewById(R.id.button_2);
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent myIntent = new Intent(v.getContext(), Class2.class);
startActivity(myIntent);
}
});
Class2.java
public class Class2 extends Activity
{
Button btn1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
btn1 = (Button)findViewById(R.id.button_3);
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent myIntent = new Intent(v.getContext(), Class3.class);
startActivity(myIntent);
}
});
Class3.java
public class Class3 extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main3);
Button next = (Button) findViewById(R.id.button_4);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
Intent intent = new Intent();
setResult(RESULT_OK, intent);
finish();
}
});
清单.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.and.roidu.xit"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".Xit_demoActivity"
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=".Class1"></activity>
<activity
android:name=".Class1"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN1" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity><activity android:name=".Class2"></activity>
<activity
android:name=".Class2"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN2" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity><activity android:name=".Class3"></activity>
<activity
android:name=".Class3"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN3" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
谢谢你的时间!..