WynixToo WynixToo - 10 months ago 25
Android Question

how to intent a dialog when the Thread.run() finish running?

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

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.


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

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");

private Handler handler = new Handler() {

    public void handleMessage(Message msg) {
        switch (msg.what) {
            case MSG_DOWNLOADED:
                // What to do when ready, example:
                    new Intent( [yourclass].this, [yourintent].class ) );