问题
I am trying to implement this great technique of sharing preferences across two different applications while still MODE_PRIVATE.
My problem is that the first application cannot assume that the first application is installed (and vice versa) and so:
Context c = createPackageContext("com.app.first", MODE_PRIVATE);
Must be replaced by:
Context c = createPackageContext("com.app.shared", MODE_PRIVATE);
But that mandates adding that com.app.shared
for real, which translates into a second APK?
In other words, there is only one AndroidManifest.xml
per APK and only one <manifest package= >
per manifest file. Therefore only one actual package per APK?
I don't want 2 APKs per application, I only want a single APK per application.
Is there a way to achieve this?
回答1:
I am trying to implement this great technique of sharing preferences across two different applications while still MODE_PRIVATE.
Actually, that is such an anti-great technique that I just deleted my answer. Using android:sharedUserId
is risky, and downright impossible for already-deployed apps. I learned the error of my ways in the two years since I had posted my answer there.
Also, the technique doesn't work reliably, because you have no control over which apps the user installs... and uninstalls. If App A and App B share preferences by means of both using App A's copy, then when the user uninstalls App A, App B is hosed.
Therefore only one actual package per APK?
Correct.
I don't want 2 APKs per application, I only want a single APK per application.
For two applications, you have two APK files, each with their own package name.
来源:https://stackoverflow.com/questions/11803585/two-packages-in-same-apk-possible