message and bundle


How to make a message, for example to send from a thread to an activity via handler.

import android.os.Bundle;
import android.os.Message;

Bundle d=new Bundle();
d.putLong(Val.TimeKey,myField.ellapsedTime);
d.putInt(Val.FailKey,myField.mistakes);
Message m=Message.obtain();
m.setData(d);
game.handler.sendMessage(m);

The keys are unique strings for each data. In this case stored in a class called Val as static final String.

to get the data from the message you use:
Bundle data=ms.getData();
Long l=data.getLong(Val.TimeKey);







No comments:

Post a Comment