Android assigns a separate user space to each APK process, and the userid in its manifest corresponds to a Linux user (the Android system is based on Linux). Therefore, it is forbidden to access data between different apk (users) by default.
But it also provides the form of shared data between 2 different apk:
1. Share preference. /Content Provider
APK can specify interfaces and data to be read by any other apk. You need to implement the interface and share data yourself.
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. So the default is that you can access arbitrary data to each other. It can also be configured to run as a different process, with access to databases and files in other APK data directories. Just like accessing the data in this program.
For example, a company developed a number of Android programs, you can put data, pictures and other resources to focus on apk a. All apk of the company then use the same user ID, and all resources can be read from apk a.
As an example:
APK A and APK B are all C's products, so if a user logs in from APK A, then it's not necessary to log on again when you open APK B. The realization is that A and B are set to the same user ID:
* Configure the user ID in the 2 apk androidmanifest.xml:
Package= "Eoe.android.demo.a1"
Android:shareduserid= "COM.C" >
This "COM.C" is the user ID, and then PackageName APK A is the above content, APK B May
It's "com.android.demo.b1," there's no limit.
Once this is set, APK B can open the database in APK a like the local database.
APK A puts the login information under the Data directory of a. APK b reads the database under APK A at each startup to determine whether it has logged in:
Code in APK B:
Friendcontext = This.createpackagecontext (
"Com.android.demo.a1",
context.context_ignore_security);
By package name of a, you get a packagecontext
With this context, you can open the database directly.
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/extra/