0

I'm creating an Android application that will register an Observer and listen for events, I will probably use one of the suggestions by Mark in this previous question.

However, my question is, how can I create a "stub" on Android that I can use to fire events at my applications observer? For the purpose of this example, we'll assume that my app is listening for a wifi signal strength, I need to create something that will run on the emulator (or device) that will mock up data to "pretend" it has a strong/weak signal, and to relay that to my app.

Any suggestions?

Community
  • 1
  • 1
Jimmy
  • 16,123
  • 39
  • 133
  • 213

1 Answers1

1

I am no Android expert but here is my catch.

If you are implementing an observable, I believe you need to create a Service by inheriting from ServiceBase.

Also create a content provider and allow other applications to insert data. The whole notification is built into the framework so if you have a cursor, you will get notifications of change in the data.

So here are the steps:

  • You run the service and register for notifications
  • Application is getting an instance of your service and registers to get back a token
  • They use your content provider to insert event along with the token they got
  • They call the notification
  • You will be notified whenever anything changes.

I know that there are notification services built into the framework but I have never had a chance to look into it.

Aliostad
  • 80,612
  • 21
  • 160
  • 208
  • Thanks. What do you mean by `You will be notified whenever anything changes.`? Do you have any links where I can read more? Cheers – Jimmy Nov 22 '10 at 13:15
  • I have noticed that my ListAdapters get any change done to the tables even outside the application but perhaps you have to do a manual work as well: http://mylifewithandroid.blogspot.com/2008/03/observing-content.html – Aliostad Nov 22 '10 at 13:20
  • I have updated my answer because I think ListAdapters being updated was a red herring. You need to explicitly specify this, but it seems content provider is the way to go. – Aliostad Nov 22 '10 at 13:22
  • The downside is that who ever is providing the data will also need to create their own android app to supply mine with data. Is there anyway to listen to data via an API call? – Jimmy Nov 22 '10 at 17:42
  • So how else can this work anyway? If they are not creating apps, what is supposed to register with you? can you please explain a little bit more? Are you trying to register with system events (which is possible and so much easier)? – Aliostad Nov 22 '10 at 22:17