Trouble with Shared Prefs.

by JoelDuggan » Sat, 09 Oct 2010 06:36:26 GMT


Sponsored Links
 Hey there all,

I'm having a problem that i don't know how to resolve.

I have a broadcast receiver catching a call from the system.  I need
this receiver to set a flag so that the next time my app runs it can
do something different.

I am trying to do this with a shared pref but it is not working.

In the receiver I do:

      SharedPreferences sharedPreferences =
context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
      sharedPreferences.edit().putBoolean("changed", true);
      sharedPreferences.edit().commit();

Then when i start my app I check like so:

         sharedPreferences = getSharedPreferences(PREFS_NAME,
MODE_PRIVATE);
         if (sharedPreferences.getBoolean("changed", false)){
            hasChanged = true;
            sharedPreferences.edit().putBoolean("changed", false);
            sharedPreferences.edit().commit();
         }


This does not work.  If I download the file from the emulator after
the receiver has triggered it is empty.  It exists but there is no key
value pair.

What am I doing wrong?  Is there a better way to flag my app to run
differently on next startup?

Any help???

--



Trouble with Shared Prefs.

by Kostya Vasilyev » Sat, 09 Oct 2010 06:46:12 GMT


 Don't call edit() multiple times.

Every call to edit() creates a new "change session", so you're changing the
value but not committing the change, and then starting a new changeset and
committing it with no new values.

--
Kostya Vasilyev --  http://kmansoft.wordpress.com 

09.10.2010 2:36  "JoelDuggan" <joeldug...@gmail.com> :

Hey there all,

I'm having a problem that i don't know how to resolve.

I have a broadcast receiver catching a call from the system.  I need
this receiver to set a flag so that the next time my app runs it can
do something different.

I am trying to do this with a shared pref but it is not working.

In the receiver I do:

     SharedPreferences sharedPreferences =
context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
     sharedPreferences.edit().putBoolean("changed", true);
     sharedPreferences.edit().commit();

Then when i start my app I check like so:

        sharedPreferences = getSharedPreferences(PREFS_NAME,
MODE_PRIVATE);
        if (sharedPreferences.getBoolean("changed", false)){
           hasChanged = true;
           sharedPreferences.edit().putBoolean("changed", false);
           sharedPreferences.edit().commit();
        }


This does not work.  If I download the file from the emulator after
the receiver has triggered it is empty.  It exists but there is no key
value pair.

What am I doing wrong?  Is there a better way to flag my app to run
differently on next startup?

Any help???

--


Sponsored Links


Trouble with Shared Prefs.

by JoelDuggan » Sat, 09 Oct 2010 22:53:29 GMT


 Thank you very much.  That makes perfect sense.  I'll give it a try
later.



>



Trouble with Shared Prefs.

by Ruchika Gupta » Mon, 11 Oct 2010 05:41:44 GMT


 Sorry for different question. How can I identify if the contact is exported
from facebook or google or both or it is local contract
from android contact book.
How can I find that? which class or variable stores information about there
source?
Appreciate any help.
Regards
Ruchika

2010/10/9 JoelDuggan <joeldug...@gmail.com>


> >



Other Threads

1. Android 2.3 problem with startAnimation in onCreate or onStart methods

Hi,
We have a game working well in 2.1 and 2.2 versions of android (RuniK). We 
were ready to release a new version when we received a mail from a user 
using the 2.3 version to report a problem.

In the onCreate method of my GameActivity, I create a matrix of initially 
hidden views then start an animation on each view. The workflow of the game 
goes on after all onAnimationEnd methods are called. But in the 2.3 version, 
the onAnimationEnd is never called and the game is stuck with empty 
screen. If I go back to the main android screen using the home button then 
switch back to the game, the onAnimationEnd methods are called and the game 
can start.

I though the lifecycle had changed in the 2.3 version and that the starting 
of the animations should be done in the onStart method (which requires some 
heavy code modifications to be sure a game isn't started again when 
switching back) so I tried a quick test. But it didn't change anything.

I'm pretty stuck right now so we'll release a new version without the 
support for 2.3 android based devices.
Is this problem known ? If you have an idea, it'll be welcomed.

Regards,
Florian

-- 

2. VPN Manager Interfaces

Hi,

I would like to know the following:

Android provides a VPN manager class that supports creation of VPN
profiles (for PPTP, L2TP, L2TP/IPSec PSK VPN & L2TP/IPSec CRT VPN).
The package is avaiable under [platform/frameworks/base.git] / vpn /
java / android / net / vpn / VpnManager.java ]. I presume this is a
hidden class and the VPN Manager interfaces are not exported for 3rd
party applications. However, the system settings application uses the
VPN Manager intefaces.

What are the reasons why the VPN manager interfaces are not exported
at the android application manager interfaces ?.

Can any OEM add custom APIs for VPN Manager support (ofcourse in the
namespace of the relevant organization). Can they reuse VPN manager
interfaces for the same ?. Will it imapct CTS ?.

BR,
vivek.

-- 
.

3. PrivacyAppCamp in Mountain View 10 Feb 2011

4. About Encryption in Android 3.0 (Honeycomb)

5. Android release process

6. Boot on power: power on when plug in USB

7. drug list app on android market