6

I have couple of applications that implements some login logic. If lets say one application is logged to some_account@gmail.com I want that all of these applications be logged to some_account@gmail.com. If I logout I want to all application do the same. But I don't want to immediately do the same. Application itself can handle it, but it need to know if some other application is already logged in and if yes just log in for the same email address as this app. So I need to know what is the email address for which other app is logged. I need to store one string.

First I was thinking about SharedPreferences, but this is rather bad idea because there are other options (and stackoverflow is full of bad example of SharedPreferences usage between processes). Despite it I tried this. Set up sharedUserId on all apps, called createPackageContext and eventually try to get preferences. But I cannot read from it. Always I got null, even if I used Context.Mode_WORLD_READABLE - which is deprecated by the way.

Ok, lesson learned do not use SharedPreferences for that (I suppose). But everything what I need now is to store single string somewhere where it could be read by other my apps.

Maybe I should use ContentProvider? But seriously... for one string? What is the other option? I am sure that for so simple operation I really don't need Service or ContentProvider, but I actually haven't got idea how to do that.

sennin
  • 8,552
  • 10
  • 32
  • 47
  • +1 Very good question. You have explained what you want to do very well. You have also shown what options you have considered in trying to find your own solution. – Code-Apprentice Oct 05 '13 at 18:26
  • I don't know of any good way to do this other than a shared file (yeuch, fragile, insecure) or a ContentProvider. It sucks that `SharedPreferences` has taken the shared out of shared, but maybe one day... – Simon Oct 05 '13 at 18:48

1 Answers1

0

You could use a broadcast receiver. All you would have to do is send a broadcast to application B when the data changes in application A. Then application B can handle the data in the background, and store it however you need to. It might be a bit of over kill, and there could be a better way to do it, but it would work.

Bryce Meyer
  • 249
  • 5
  • 9
  • But I am not sure if all applications are running. Broadcasts are not delivered to applications which are closed or stopped by the user from settings. – sennin Oct 08 '13 at 10:58