Unable to access Honeycomb readable preferences

I have a free game and I'm making a paid version. The free game stores an integer high score in the general preferences file that I created in MODE_WORLD_READABLE mode. The paid version must copy this account if the free version is installed.

The code I use for this is as follows:

Context c = paidContext.createPackageContext("my.app.packagename", Context.CONTEXT_IGNORE_SECURITY); SharedPreferences prefs = c.getSharedPreferences(SHARED_PREF_FILENAME, Context.MODE_WORLD_READABLE); 

The first line creates the context for the free application if it exists (otherwise you get an exception). The second line gets the file of general preferences. Then I can use prefs.getInt to get a high score.

Problem: this works fine in Android 1.5, 2.1, 2.3, etc., but it does not work for me in Android 3.0 or 3.1 emulator. The code above is executed, but getInt always returns the default value.

This is mistake? Honeycomb Feature? Are there any rights to the application that I don’t know about? How can I diagnose this further?

+4
source share
1 answer

Although useful, a Roman commentary on the question does not provide an answer. To expand it, Android does not guarantee that preferences will be available for all processes; In fact, the documentation (at the top of SharedPreferences ) clearly indicates that interprocess access is not supported (although it does work, sometimes). By signing applications with different certificates, you guarantee that the applications will not be able to work in the same process, which is the Android method for the sandbox.

In this case, I tried to use SharedPreferences with MODE_WORLD_READABLE as a means to access data between two applications written differently. In the end, I ran into problems due to some cases where reading between processes did not work (it seemed to be an operation of an order of operations). Instead, I implemented what I had to do first, which is interprocess communication (IPC) using Service + AIDL .

+1
source

All Articles