I am stuck on sync real time data between 2 app only in Oreo+ devices, Like if different user login to the app then it should be immediately effect in other app and It should also change in other app.(e.g. Facebook and Facebook Messenger. If you logout from Facebook, it will automatically logout from FB Messenger or If you log into Facebook then it will automatically logged into FB Messenger and vice versa) I created broadcast receiver in both app and if login changes from one app then send broadcast to other app where it will do rest of work.
I have googled on it and I found some ways.
I have read this document
https://developer.android.com/about/versions/oreo/background
- We have published differently signed APKs so not able to provide same signature permission in receiver.
Already went through this links
Broadcast receiver not working in oreo
Oreo: Broadcast receiver Not working
Broadcast receiver registered in manifest not getting called in Android Oreo
Receiver stopped receiving in Oreo
Thought to implement this ways but..
1) Create foreground service and register receiver into it. - As this way, I need one notification which is required to run foreground service. and I can't do that.I can't show unnecessary notification.
2) Scheduled job: - I can't use it as I need to run service all time in background.
What I have tried so far:
1) Register receiver in Application class : This is not working after application is killed because context has been killed.
2) Registering receiver in FireBase Notification service, but it's only initialize when notification arrives.
Code:
Registering receiver in Application class
ASampleActionReceiver mASampleActionReceiver = new ASampleActionReceiver();
IntentFilter filterAction = new IntentFilter();
filterAction.addAction("com.sample.example.receiver.operation");
registerReceiver(mASampleActionReceiver, filterAction);
In Manifest
<receiver android:name=".receiver.ASampleActionReceiver">
<intent-filter>
<action android:name="com.sample.example.receiver.operation" />
</intent-filter>
</receiver>
Intent service will start by receiver
<service
android:name="com.sample.example.services.SampleOperationService"
android:enabled="true"
android:exported="false" />
And a Receiver ASampleActionReceiver.java
public class ASampleActionReceiver extends BroadcastReceiver {
Context mContext;
@Override
public void onReceive(Context context, Intent intent) {
mContext = context;
AdoddleLog.d("LOG", intent.getExtras().getString("loginData"));
Intent mIntent = new Intent(mContext, SampleOperationService.class);
mIntent.putExtras(intent);
mContext.startService(mIntent);
}
}
can some one please suggest better solution?
Can I use AIDL for app communication ? does it work if any one application is idle or not running in background ?