2

We have an old app with a set of functionality (services). We also have a new app that has started to implement some of the old app's functionality. Our goal is that when someone start to use the service in the new app, we want the old app to turn off these services.

My first thought was a very simple mechanism, like setting a flag (in SharedPreferences) and somehow let the old app query this flag, and then shut down its services.

I've read about MODE_WORLD_READABLE and SharedPreferences, but that is no longer recommended. So does anyone have a good approach/solution for this?

PS! The apps are signed with different certificates, but both are developed by us.

Ahmad Aghazadeh
  • 16,571
  • 12
  • 101
  • 98
Christian
  • 915
  • 1
  • 8
  • 13
  • so you have to modify your old app anyway... then simply add "switch off" request – pskink Nov 19 '16 at 09:31
  • @pskink I did not quite understand that comment, but yes we have to modify the old app, but it is crucial that the old app does not stop it's service before it knows for sure the new app has started it. (backup service) – Christian Nov 19 '16 at 09:36

3 Answers3

1

BroadcastReceiver, receiving system-wide Broadcast Intent sould work fine. Newer version of app will send 'newer version activated' intent, and, if there is older version running, it will receive that broadcast and switch off those services.

Alex Shutov
  • 3,217
  • 2
  • 13
  • 11
1

Hi you can use ContentProvider ContentProvider

Or use SharedPreferences

Set sharedUserId in both like com.example apps to be same .

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hello"
android:versionCode="1"
android:versionName="1.0" 
android:sharedUserId="com.example">

Get Context from package:

mContext = context.createPackageContext(
                        "com.example.otherapp",
                        Context.MODE_PRIVATE);
 mPrefs = mContext.getSharedPreferences("sameFileNameHere", Activity.MODE_PRIVATE);
Ahmad Aghazadeh
  • 16,571
  • 12
  • 101
  • 98
0

Content provider is definitely the one solution for you.

Other option is to pass data between processes, it needs to be marshaled and unmarshaled accordingly. This marshaling and unmarshmaling of data to primitive types is so the OS can understand it passing over inter process communication (IPC) can be tedious and error prone if done manually. Android interface definition language (AIDL) helps solve this problem.

follow here

http://developer.samsung.com/technical-doc/view.do;jsessionid=C7B3534740D7D9C4B3A7E44D08D55D75?v=T000000110

http://codetheory.in/android-interprocess-communication-ipc-with-aidl/

Rissmon Suresh
  • 13,173
  • 5
  • 29
  • 38