用这个 -
Intent intent = new Intent(Activity3.this, FinishActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
finish();
已编辑--新答案,可以完美运行..
只是举个例子......根据您的项目需要做它 -
我正在参加三个Activity
A、B 和 C 类课程。我在 C 类活动视图上应用了一个关闭按钮。如果你愿意,然后通过后退按钮,你可以转到上一个活动,当你按下关闭按钮时,你会退出应用程序......看看 -
public class AActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent i = new Intent(this, B.class);
startActivityForResult(i, 1);
}
@Override
protected void onActivityResult(final int requestCode,
final int resultCode, final Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (resultCode == 5) {
finish();
}
}
}
参加下一节课的活动——
public class B extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.b);
Intent i = new Intent(this, C.class);
startActivityForResult(i, 2);
}
@Override
protected void onActivityResult(final int requestCode,
final int resultCode, final Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (resultCode == 5) {
setResult(5);
finish();
}
}
}
做最后一个活动——
public class C extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.c);
}
// close button..set by xml view..you can set it by button listener.
public void close(View v) {
setResult(5);
finish();
}
}
希望它能解决您的问题..干杯!