I have an app A and app B, the apps are signed with the same certificate. App A has a checkbox preference, app B needs to know is the preference checked or not.
I came up with an idea to broadcast an intent with needed Boolean value been set on every change of the checkbox state in app A. Having a unique action for this intent together with a custom permission that has signature
protection level should guarantee that only app B will receive such intent in its BroadcastReceiver
.
Together with it I considered using ContentProvider
, which looked like not the best option to me.
for using it I need to override a bunch of CRUD methods that won't be used in my particular case. Only one flag will be shared, so there is no need to communicate with a database.
Also I looked at binding to a Service
, which is located in app B, from app A using a Messenger
. In this case I get a Handler
, and when a user checks or unchecks the setting, I can send a message with an appropriate argument to app B. But such approach brings some problems to the table with binding/unbinding to the service (leak connection possibility or excess connections).
The problem I faced with is that app B must have a possibility of asking the state of the checkbox in app A. For example if the user reinstalls the app B.
In other words, I can notify app B about changing of the checkbox state from app A, but how I can ask app A about that state from app B?
Sending sticky broadcasts from A to B would fix the problem, but sticky ones are deprecated in API level 21 because of possible security vulnerabilities.