In my activity, i have a progress dialog and i need to perform some action if some one presses the back button. When i use onBackPressed th开发者_运维知识库en its no good.How to handle such thing?
add a cancel button to progress dialog. Maybe these helps Why is there no cancel button in Android's progress dialogs?
And you should use thread and handlers to do what you want.
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
}
};
精彩评论