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. Rounded Rectangle with one side missing

I am trying to find a way to create a rounded rectangle with one side
missing.  Something like this :

------------------------
|
------------------------


Currently, I am using a 9 patch, which works pretty well, but the
requirements just changed to allowing user changeable colors.   I've
spent the last few days trying to figure out a way to make this
happen, and have not managed to come up with a solution.

I found a post about changing the colors of an image in code, but it
won't work because I need the image to scale correctly when text is
written on it.  (Which is why I am currently using a 9-patch.)

Other posts talk about using shape XML, which gets me really close.
I can generate the tab the way I want, but I can't seem to find a way
to remove the line on the right side of the shape.

I have also looked at using the Path() class, but it seems that you
have to have a path that is fully enclosed.  This would work, except I
need a stroked line border with the area in the middle filled.   Which
basically puts me in the same situation as using the shape XML.

Has anyone done anything like this?  Or have any ideas that might help
me along?

Thanks!

-- 

2. Building kernel and loading with Emulator

Hi,

    I am new to Android but i have experience with linux device
driver.
I want to finally write a driver and a small apllication to use this
driver.

For this first i wanted to first compile the kernel and load using the
Emulator.

Here is what i did.

1. Since I have 32 bit Ubuntu 10.10 installed on my laptop, I
downloaded Android 2.2 froyo platform code as Gingerbread and onwared
needs 64 bit linux.

$ repo init -u git://android.git.kernel.org/platform/manifest.git -b
froyo
$ repo sync
$ source build/envsetup.sh
$ lunch full-eng
$ make

I could successfully build this code.

2. Downloaded the kernel (2.6.36) code using
git clone git://android.git.kernel.org/kernel/common.git

I could build this for ARM after changing task to tsk and disable DRM
module

make ARCH=arm CROSS_COMPILE=arm-eabi-

3. Now i am trying to load this kernel and load using the emulator

santosh@ubuntu: cd out/target/product/generic
santosh@ubuntu:~/out/target/product/generic$ emulator -kernel kernel/
arch/arm/boot/zImage -system system.img -ramdisk ramdisk.img -initdata
userdata.img
emulator: WARNING: ignoring locked user data image at /home/santosh/
out/target/product/generic/userdata-qemu.img
emulator: WARNING: Another emulator is running. user data changes will
*NOT* be saved
emulator: ERROR: There is no user data image in your build directory.
Please make a full build

I got these above warnings when I used -data userdata.img option as
well.


My questions are

1. Am i following the correct steps?
Do I need goldfish branch kernel or latest branch is ok?

Can you point me to any link/discussion on similar topic?

2. I have installed eclipse-SDK-3.6.2-win32 and latest android-sdk-
windows on my Windows vista laptop.
Can I copy the kernel image from my Ubuntu system to my Windows system
and test on windows emulator

android-sdk-windows\platforms\android-11\images has these files.

04/07/2011  09:19 PM         1,466,272 kernel-qemu
04/07/2011  09:19 PM           149,161 ramdisk.img
04/07/2011  09:19 PM       115,993,152 system.img
04/07/2011  09:19 PM         2,916,672 userdata.img

What files should i copy and from which locations?


Thanks
-Santosh

-- 

3. how to make a boot-disk?

4. Conflict in to MapController between Zoom Level and AnimateTo ?

5. Invalidating a Canvas view that is part of setContentView()

6. Porting of OpenGL on powerpc board

7. Original posting