在我的活动中,我有一个进度对话框,如果有人按下后退按钮,我需要执行一些操作。当我使用onBackPressed然后它没有好处。如何处理这样的事情?
答案 0 :(得分:0)
为进度对话框添加取消按钮。也许这些有助于Why is there no cancel button in Android's progress dialogs?
你应该使用线程和处理程序来做你想做的事情。
ProgressDialog dialog = ProgressDialog.show(MyActivity.this, "",
"Loading. Please wait...", true);
Thread t = new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
dialog.Show();
}
});
t.Start();
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
handler.sendemptymessage(0);
}
private Handler hanlder = new Handler(){
public void handleMessage(Message msg) {
t.Stop();
//dialog.dismiss(); try these if stoping thread don't work
}
};