1

I am working on two applications of same company. My requirement is "When I install two fresh applications and do login to one application, it should automatically login to another application. And when I logout from one application, same user should also log out from another application."

For example. I have 2 applications.

  1. Facebook
  2. Facebook Messenger.

When I log into Facebook from user "John", so when I open Facebook messenger, it is already logged in with user "John". And when I log out from Facebook app, that user should also logged out from Facebook Messenger. And vice versa.

How can I achieve this functionality in Android? Actually this functionality is working in below oreo devices.

Here is what I tried to implement.

Code

Registering receiver in Application class of both applications.

ASampleActionReceiver mASampleActionReceiver = new ASampleActionReceiver();
IntentFilter filterAction = new IntentFilter();
filterAction.addAction("com.sample.example.receiver.operation");
registerReceiver(mASampleActionReceiver, filterAction);

In Manifest of both applications.

<receiver android:name=".receiver.ASampleActionReceiver">
    <intent-filter>
        <action android:name="com.sample.example.receiver.operation" />
    </intent-filter>
</receiver>

We have intent service in both applications. 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);
    }
}

But device which has android 8.0+ OS , Receiver not working, because https://developer.android.com/about/versions/oreo/background https://developer.android.com/about/versions/oreo/android-8.0-changes#back-all

So how can I achieve this?

Kush Patel
  • 1,228
  • 1
  • 13
  • 34
  • You need to use contect provider to have a inter app communication. – Abdul Waheed Nov 20 '18 at 12:50
  • use content provider, according to my logic when you are logging in and out i think you are saving a flag somewhere (eg :shared preferenve) that you are currently logged In. so when you logout from one application you just clear the shared preference – Jins Lukose Nov 21 '18 at 09:20
  • Perfect Solution https://stackoverflow.com/questions/53370019/android-not-able-to-sync-data-between-applications-above-oreo-devices/53758083#53758083 – Kush Patel Dec 14 '18 at 10:55

0 Answers0