Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Toast message from Broadcast Receiver

Tags:

I have a broadcast receiver and I am trying to show a toast message from it, is this possible ? This code doesn't show the toast but it print the log message in the logcat. Is there some idiotic thing I am doing or what is my problem ?

@Override public void onReceive(Context context, Intent intent) {     Log.v("log", "this is shown");     Toast.makeText(context, "this is not shown"     , Toast.LENGTH_LONG); } 
like image 618
Lukap Avatar asked Oct 26 '11 09:10

Lukap


People also ask

What does message from broadcast receiver mean?

Broadcast in android is the system-wide events that can occur when the device starts, when a message is received on the device or when incoming calls are received, or when a device goes to airplane mode, etc. Broadcast Receivers are used to respond to these system-wide events.


2 Answers

Call the show() method for the Toast.

like image 59
user Avatar answered Sep 17 '22 19:09

user


you forgot to call show() on the Toast.. although i would not recommend creating toasts from BroadcastReceivers.. you might consider using Notifications

like image 35
lukuluku Avatar answered Sep 20 '22 19:09

lukuluku