I have developed a application with two activities, activity1 and
activity2 ,and one local service, service1  . activity1  is the main
activity. activity2 has a button. when button is pressed. show a
progress dialog. and local service start doing some stuff. when it's
done. send msg to activity2 to close progess dialog.  the first time
start activity2, everything is ok. but then back to activity1 and re-
enter activity2, press button to show the progress dialog, it did not
hide.from log i saw the hide msg is cought and when handler try to
close the dialog, found out that it is null !.

anybody has any idea what is wrong here?

public class Activity1(){

    button1.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View vw)
            {

                //start activity2
            }
        });
}

public class Activity2(){

    private ProgressDialog pb = null;

    private Handler mHandler = new Handler() {
         public void handleMessage(Message msg) {
            if (msg == HIDE)
                 if (pb != null) {   // pb always is null here after
activity2 back to activity1 and re- entered activity2.
                                        //   and the progress dialog
never hide.
                 pb.cancel();
                 pb = null;
                 }
        }
    }
    button2.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View vw)
            {
                  pb = ProgressDialog.show(
                       this,
                       null,
                       "Please wait...",
                       true,
                       false);

                service1.doStuff();
                   //service1  start to do some stuff.
            }
        });

     public void onStart(){
         //bind to service1. when bound. set activity1's handler to
service1
    }

    public class Service1 {
          mHdler = activity1 's mHandler;

          public void doStuff () {
               //start a thread to do somthing
              Thread td = new Thread (runnable)
              td.start();
          }

     Runnable runnable = new Runnable (){
            public void run() {
                   //do some time consumed stuff.
                   ....
                  //done, send hide pb msg to activity2
                  Message msg = Message.obtain();
                  msg.what = GeoRecorderUtil.MSG_ERROR_UNKNOWN;
                  mHdler.sendMessage(msg);

            }
    }
    }
}

--~--~---------~--~----~------------~-------~--~----~
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