Thursday, 15 July 2010

java - SharedPreferences between different apps works on emulator, not on device -



java - SharedPreferences between different apps works on emulator, not on device -

i'm trying save keys sharedpreferences on first app, when initialized sec app, load them. works on emulator not on device (android 4.0.3)

this code on first app:

private sharedpreferences gamesaved; private sharedpreferences.editor editor; gamesaved = getapplicationcontext().getsharedpreferences(prefs_name, context.mode_private); int value = 10; editor = gamesaved.edit(); editor.putint("value_0", value); editor.commit();

then on sec app key value this:

try{ con = getapplicationcontext().createpackagecontext("com.example.firstapp", 0); } grab (namenotfoundexception e) { } sharedpreferences pref = con.getsharedpreferences(prefs_name, context.context_ignore_security); int value = pref.getint("value_0", -1);

on manifest both apps share line:

android:shareduserid="com.example.shared"

i've check sharedpreferences file correctly created , located. unusual thing works on emulator. please help, i'm running out of ideas.

i solve don't have technical explanation it.

previously had on both apps same file name it:

sharedpreferences pref = con.getsharedpreferences(file_name, context.context_ignore_security);

it doesn't have much sense because files stored/saved in different app's info folder if share same sharedpreferences file name won't work (at to the lowest degree me).

java android sharedpreferences emulator

No comments:

Post a Comment