Thread.run()完成运行后如何设置对话框?

Wyn*_*Too 0 android android-activity

我正在开发一个下载管理器功能,当项目下载完成后,对话框将弹出.下载功能在后台运行.

我的问题是如何知道下载何时完成以及项目是否意图进行其他活动?

例如:

if(download_state == TASK_FINISH){
    //download Finish
    openfile();
    }
Run Code Online (Sandbox Code Playgroud)

我应该把上面的方法放在哪里?我尝试将它放在用户打开的每个活动中的onResume(),onStart()上.但不幸的是它不起作用.你的回复表示赞赏.

p/s:我很抱歉我的英语不好,希望你们能理解我在说什么.

谢谢.

oni*_*nik 9

这是我正在使用的方法.可以有更好的方法,但这对我有用.

public static final int MSG_DOWNLOADED = 0;
//to demonstrate the background process
ProgressDialog pd;

pd = ProgressDialog.show(this, "title", "text", true, false);
new Thread() {
    public void run() {
        // Download image then continue
        // For Example: downloadImg("file");
        handler.sendEmptyMessage(MSG_DOWNLOADED);
    }
}.start();

private Handler handler = new Handler() {

    @Override
    public void handleMessage(Message msg) {
        switch (msg.what) {
            case MSG_DOWNLOADED:
                pd.dismiss();
                // What to do when ready, example:
                [yourclass].this.startActivity(
                    new Intent( [yourclass].this, [yourintent].class ) );
                break;
            }
        }
    };
}
Run Code Online (Sandbox Code Playgroud)