我有活动A,有计时器线程。 5秒后,它会通过意图跳转到活动B.当你在活动B上时如何销毁活动A,这样后退按钮就不会让你回到活动A.
答案 0 :(得分:1)
您必须清除活动后台堆栈。
intent = new Intent(this, Activity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
StartActivity(intent);
答案 1 :(得分:0)
从A到B
制作意图时,只需致电finish()
答案 2 :(得分:0)
试试这个......
<强> MainActivity.java:强>
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new Waiting(5);
}
public class Waiting {
Timer timer;
public Waiting(int seconds) {
timer = new Timer();
timer.schedule(new WaitingTask(), seconds * 1000);
}
class WaitingTask extends TimerTask {
@Override
public void run() {
System.out.println("Hi, I'm waiting here!");
Intent intent = new Intent(MainActivity.this,
MainActivity1.class);
MainActivity.this.finish();
startActivity(intent);
timer.cancel();
}
}
}
}
<强> MainActivity1.java 强>
public class MainActivity1 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_activity1);
}
}
快乐的编码......