Question

The premise is I am writing a library that in itself uses and implements the IBeacon SDK. My code has to implement that SDK, does things and if someone uses my library they dont have to interact with this SDK at all, so I'm making a higher level codebase you could say.

Now my code cannot use any activities by itself, its just a library, another user will then implements my code. So my code needs to consume the IBeacon events and do something with it without being an activity by itself.

So I would implement IBeaconConsumer myself and then the person using my library would just give me an activity / context and I would pass it to the IBeacon SDK.

Doing so results in the following problem (with proper mainfest code):

The activity binds its iBeaconManager object however onIBeaconServiceConnect never gets called. See this stackoverflow question: Android IBeaconManager not connecting from activity

My vague assumption is this: the class implementing IBeaconConsumer is not an activity and its not the same class as the one I am binding the IBeacon service to and that might create the problem. Its just very hard to debug since it all works, no errors, just no ibeacon activity - same behavior as if you forget to add the part in the manifest

Was it helpful?

Solution

If you want your IBeaconConsumer implementation to not be an instance of Activity or a Service, then you simply need to chain the bindService and unbindService methods to a valid ApplicationContext instance, and return that valid instance from the getApplicationContext method. This is not needed when you are implementing this interface with an Activity, because an Activity implements these three methods for you.

You can see an example of this in a related question here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top