我使用postDelayed方法来刷新我的Activity,这很有效。但问题是,即使我按下返回按钮,postdelayed方法仍然会回调到先前的Activity。
//用于30000毫秒后延迟刷新Activity的handler
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();
}