我使用了publishDelayed方法来刷新我的Activity,这很好用.但问题是,即使按下后退按钮后延迟方法,也可以回调上一个活动.
//延迟刷新活动后30000毫秒的处理程序
mHandler.postDelayed(new Runnable() {
public void run() {
dostuff();
}
}, 30000);
}
protected void dostuff() {
Intent intent = getIntent();
finish();startActivity(intent);
Toast.makeText(getApplicationContext(), "refreshed", Toast.LENGTH_LONG).show();
}
public void onBackPressed() {
super.onBackPressed();
finish();
mHandler.removeCallbacks(null);
}
protected void onStop() {
mHandler.removeCallbacks(null);
super.onStop();
}
Run Code Online (Sandbox Code Playgroud)