views:

70

answers:

1

Hello, I've got to missing something completely stupid on this one since updating a TextView should be an easy task. I have an Activity class that is an observer of another that receives messages. In my Activity's onCreate I do the following and it works fine.

theStatus = (TextView) findViewById(R.id.theStatus);

theStatus.setText("waiting");

Later when the message activity receives a new message it hands it off to it's observer (my Activity)

public void statusUpdate( GenericMessage aMessage )

{

String statusText = aMessage.getDetails();

theStatus.setText(statusText);

theSessionStatus.invalidate(); // I've tried with and without this call

}

However the screen doesn't update. I must be overlooking something... Thanks for any input!

A: 

It looks like I found a solution, although it feels like a hack. I got the idea from your comments above and from here.

I am now using a Handler to notify the Activity B that a message has come in that it is interested in. B creates a Handler in its onCreate:

  Handler statusHandler = new Handler();
  statusHandler.post(new Runnable() 
  {
      public void run()
      {
         statusUpdate();
      }
  });

I updated the message receiver class C (that B was trying to be an Observer of) to take in the Handle when B registers with it. Then in C, I call the following when the applicable message comes in:

theMsgObserverHandle.post(new Runnable()
{
   public void run()
   {
      Log.d(myName, "Calling my Observer statusUpdate");  

      theMsgObserver.statusUpdate();
   }
});

What I don't like is that now I can't just pass my message to B directly. (My message class is my own defined class not android.os.Message) Instead now in B I need to ask the instance of C (C is a Singleton) for the message. But at least I'm moving forward. If anyone has a better implementation I'd really appreciate the feedback.

cbursk
Odd, on further reading it seems like I should not have to call the first statusHandler.post that I have in my onCreate, but if I take it out, while statusUpdate is called and no longer throws an exception the setText doesn't work.
cbursk