开发者

How to Handle ProgressDailog when backkey is pressed in android?

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

    }

};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜