Hi,
I'm trying to display a message to the user some time after an event is received by a BroadcastReceiver.
public class MyReceiver extends BroadcastReceiver {
private Timer timer = new Timer();
@Override
public void onReceive(Context context, Intent intent) {
// Display message in 10 sec.
timer.schedule(new MessageTask(context, "Test Message"), 10 * 1000);
}
private static class MessageTask extends TimerTask {
public MessageTask(Context context, String message) {
this.context = context;
this.message = message;
}
public void run() {
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
}
}
}
When I run this I get the following exception:
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
Is this the right way to do something like this? Should I be using something other then a Timer? And what is the right way to get a Context object in this situation?
Thank you