开发者

How to Handle ProgressDailog when backkey is pressed in android?

开发者 https://www.devze.com 2023-02-26 11:47 出处:网络
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

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

精彩评论

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