我有两个活动A和B.我想从A活动转到B活动时重启B活动,我该怎么做?
Intent send_show = new Intent(A.this, B.class);
startActivty(send_show);
答案 0 :(得分:1)
要“重新启动”,您只需执行此操作:
Intent send_show = new Intent(B.this, A.class);
finish(); //here restart the B because you are on B class
startActivty(send_show);
否则您可以拨打recreate()
由于您想要“重新启动”计时器,您可以执行以下操作:
public void onDestroy(){
super.onDestroy();
//you should restart timer or just cancel and re active it in onCreate()
}
答案 1 :(得分:0)
你的意思是你只需要处理Timer?
public Timer rebuildTimer(Timer timer){
try{
if(timer!=null){
timer.cancel();
timer = new Timer();
}
}catch(Throwable e){
}
return timer;
}
private Timer mTimer;
private void onNewIntent(){
mTimer = rebuildTimer(mTimer);
}
private void onCreate(Some params){
mTimer = rebuildTimer(mTimer);
}