views:

19

answers:

1

Hi, I'm develop a download manager function which the dialog will popup when the the item was finished download. the download function was running at background.

my question is how can I know when the downloading was finished and the project is intent other activity?

for example:

if(download_state == TASK_FINISH){
    //download Finish
    openfile();
    }

the above method where should I put? i try put it at onResume(), onStart() in every activity which will open by user. but unlucky it won't work.You reply is appreciated.

p/s: I'm sorry about my bad english, hope you guys understand what I'm talking about.

Thank you.

+1  A: 

Hi,

this is the method I'm using. There can be better ways but this works for me.

//to demonstrate the background process
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); // public static final int MSG_DOWNLOADED = 0
    }
}.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:
                openFile();
                break;
            }
        }
    };

Hope this helps :)

edit: Didn't read the question that carefully, replace openFile with:

Intent intent = new Intent([yourclass].this, [yourintent].class);
[yourclass].this.startActivity(intent);
onik
it work!! thanks onik. Thank you very much~
WynixToo