Android assigns a separate user space to each APK process. The userid in its manifest corresponds to a Linux User (the Android system is based on Linux. therefore, mutual access to data between different APK (users) is disabled by default.
However, it also provides two types of APK data sharing:
1. Share Preference./Content Provider
APK can specify interfaces and data to read from any other APK. You need to implement interfaces and Share data on your own.
2. Shared User id
With the Shared User id, multiple APK with the same User id can be configured to run in the same process. by default, the system can access any data from each other. you can also configure to run different processes and access the databases and files in the data directory of other APK files. just like accessing the data of this program.
For example, if A company develops multiple Android programs, you can put data, images, and other resources in apk. then all the company's APK uses the same User ID, so all resources can be read from apk.
For example:
Both apk a and apk B are products of Company C. If the user logs in from APK A successfully. you do not need to log in again when you open apk B. the specific implementation is to set A and B to the same User ID:
* Configure the User ID in AndroidManifest. xml of two APK files:
Package = "eoe. android. demo. a1"
Android: sharedUserId = "com. c">
This "com. c" is the user id, and packagename apk a is the above content. apk B may
Is "com. android. demo. b1 ".
After this setting, apk B can open the database in APK A just like opening the local database.
Apk a stores the login information in the data directory of A. apk B reads the database under APK A each time it starts to determine whether it has been logged on:
Code in apk B:
FriendContext = this. createPackageContext (
"Com. android. demo. a1 ",
Context. CONTEXT_IGNORE_SECURITY );
You can use package name of A to obtain packagecontext of.
With this context, you can directly open the database.