Android: Retrieving shared preferences of other application

Okay! using this code in Application 1 ( with package name is “com.sharedpref1” ) to store data with Shared Preferences. SharedPreferences prefs = getSharedPreferences(“demopref”, Context.MODE_WORLD_READABLE); SharedPreferences.Editor editor = prefs.edit(); editor.putString(“demostring”, strShareValue); editor.commit(); And using this code in Application 2 to get data from Shared Preferences in Application 1. We can get it because we use … Read more

Sharing a variable between multiple different threads

Both T1 and T2 can refer to a class containing this variable. You can then make this variable volatile, and this means that Changes to that variable are immediately visible in both threads. See this article for more info. Volatile variables share the visibility features of synchronized but none of the atomicity features. This means … Read more

How to share semaphores between processes using shared memory

It’s easy to share named POSIX semaphores Choose a name for your semaphore #define SNAME “/mysem” Use sem_open with O_CREAT in the process that creates them sem_t *sem = sem_open(SNAME, O_CREAT, 0644, 3); /* Initial value is 3. */ Open semaphores in the other processes sem_t *sem = sem_open(SEM_NAME, 0); /* Open a preexisting semaphore. … Read more

Shared library in containers

Actually, processes A & B that use a shared library libc.so can share the same memory. Somewhat un-intuitively it depends on which docker storage driver you’re using. If you use a storage driver that can expose the shared library files as originating from the same device/inode when they reside in the same docker layer then … Read more

tech