In the code showed as below i create a process dialog for doing some long
operation (in this case waiting
4 seconds)... It runs as it should. And shows the "Starting..." and "Done"
message but when it finishes
and i click Button1 again it terminates. What am i doing wrong?

----- code -----

public class main extends Activity {
public ProgressDialog dialog = null;

final Handler handler = new Handler(){
public void handleMessage(Message msg){
 dialog.dismiss();
TextView tv2 = (TextView) findViewById(R.id.TextView02);
 tv2.setText("Done");
}
};
 Thread runlongjob = new Thread(){
public void run(){
SystemClock.sleep(4000);
 handler.sendEmptyMessage(0);
}
};
     /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

    }
    public void clickhandler(View v){
     switch(v.getId()){
     case (R.id.Button01):
TextView tv1 = (TextView) findViewById(R.id.TextView01);
     tv1.setText("Starting...");

     dialog = ProgressDialog.show(main.this, "Please wait", "Doing Job...",
true);
     runlongjob.start();
     break;
     }
    }

}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to