-1

here is my hander:

   public Handler handler = new Handler(){

    @Override
    public void handleMessage(Message msg) {
       super.handleMessage(msg);
        String mmsg = msg.getData().getByteArray("msg").toString();
        Toast.makeText(clientActivity.this, mmsg,Toast.LENGTH_LONG).show();

    }

};

I send data from separate thread:

    public class client implements Runnable
{
    private void showtoast(byte[] msgtoshow){
        try {
            Bundle mbundle = new Bundle();
            Message greeting = new Message();
            mbundle.putByteArray("msg", msgtoshow);
            greeting.setData(mbundle);
            handler.sendMessage(greeting);
        }catch(Exception e){
            Log.d("error",e.getMessage());
        }
    }

    public void run()
    {
      msgstrng = "this is supposed to be some text";
      showtoast(msgstrng.getBytes());
    }

} Instead of line that I send in msgstng I toast some [B@411dd11] which is always different. I guess it's timestamp or smth. how to get that String value msgstng? Actually more important for me is to get bytes array, as I'll send bitmaps from socket to UI if i learn this issue

asanovrus
  • 1
  • 2
  • If the message is passed within a single process it seems like overkill to use a `Bundle` just to pass a `String`. Instead you could use `Message greeting = handler.obtainMessage(MY_MESSAGE_ID, new String(msgtoshow));` and then `String mmsg = (String) msg.obj;` in `handleMessage`. (if you change `showtoast` to take a `String` you could get rid of the `new String()` call) – Michael Sep 18 '15 at 12:49

1 Answers1

0

The problem seems to be the way you are getting the string in your Handler.

Try something like this:

String mmsg = new String(msg.getData().getByteArray("msg"));
tato.rodrigo
  • 2,783
  • 21
  • 26