-1

i want to create a BroadcastReceiver which listens to some event. Now i also want to write to a screen which is loaded from my mainactivity.

I can't seem to find an example where a BroadcastReceiver is registered and writes, in it's onReceive event, to the screen which is associated with the main activity.

Michel
  • 23,085
  • 46
  • 152
  • 242
  • what do you mean screen ? the UI or an open gl surface? – Guru Sep 25 '13 at 19:28
  • What does "a screen" mean? And how do you "write" to one? Do you mean that you want the UI of your activity to update based upon the broadcast? – CommonsWare Sep 25 '13 at 19:39
  • good questions; i'm not so familiair with the Android terminology. With 'the screen' i mean the associated form/screen/window which is an xml file in my Exclipse project to which i can communicate from an activity. – Michel Sep 26 '13 at 06:12

1 Answers1

1

How complex is the information you want to show on the screen?

  • If it's just a short message, you can use Toast
  • If it's a kind of status use Notification
  • If it's a button or a single text in an AppWidget use RemoteView
  • Anything more complex then that can only be done from within an Activity. In this case you would create an Activity with your BroadcastReceiver as inner class an would initiate changes by calling Activity.runOnUiThread
jboi
  • 11,324
  • 4
  • 36
  • 43
  • Hi, i think this comment `In this case you would create an Activity with your BroadcastReceiver as inner class an would initiate changes by calling Activity.runOnUiThread` triggered me . I've used this example http://stackoverflow.com/questions/6362314/wifi-connect-disconnect-listener (the 'Tanner'answer) in my activity, but it didn't work. I've put the code in the start event of my activity, but the `onreceive` method was never called. Also, Eclipse signed that the `receiver` is never used? – Michel Sep 26 '13 at 10:33
  • First thing to look at is the Manifest. Did you register the receiver with the right intent filter? If this is ok, why not asking a new question in Stackoverflow? – jboi Sep 26 '13 at 11:13
  • I guess i was more looking for the answer on the 'why doesn't it work'question then which code to use. I'll look at the register and see wether there are mistakes there. – Michel Sep 26 '13 at 11:24