Search code examples
androidmessage-passing

How can I broadcast simple data (ticks) to other listening android apps?


I have written 2 android apps. One is a keyboard, the other is a typing speed measurer.

I would like to broadcast a "tick" to any other apps that are listening (or to nobody at all, if none are listening), whenever a key in the keyboard app is released. I don't want this broadcast to launch the other app (if it is not running), but if it is awake and in the foreground, I want the second app to be able to count these ticks to determine how many keys have been pressed in the first app (independent of their text output).

I thought broadcasting an Intent would be a good way to accomplish this, but it appears that that will launch the second app.

A SharedPreference would also work, but that doesn't seem like the correct tool for the job.

Any better suggestions?


Solution

  • Broadcasting an intent will not launch the second app. I think you're confusing it with Context.startActivity().

    Use Context.sendBraodcast(): http://developer.android.com/reference/android/content/Context.html#sendBroadcast(android.content.Intent)