Hi jason, that works! Thanks for pointing me to it. On Thu, Nov 6, 2008 at 10:40 AM, Jason Parekh <[EMAIL PROTECTED]> wrote: > The SharedPreferences keep a cache in memory. So, when you remove the file, > it ends up using the cached value (false) from memory. > > Try rm'ing the file, killing your process (from Devices tab in eclipse), and > then relaunching. > > jason > > > On Wed, Nov 5, 2008 at 3:30 AM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> > wrote: >> >> Hi, >> I noticed an interesting but unexpected behaviour with preference >> processing in Android. Here's what I'm trying to do. >> My app needs to perform some specific tasks when it is launched for >> the first time after installation. I use an element named >> "firstLaunch" for this purpose. I set its value to false in the first >> launch so that subsequent launches will see it properly. >> >> Here's the piece of code: >> >> package com.example; >> SharedPreferences prefs = getSharedPreferences("pref", >> MODE_PRIVATE); >> isFirstTimeLaunch = prefs.getBoolean("firstLaunch", true); >> Log.d("readPreferences", "read first time launch value: " + >> isFirstTimeLaunch); >> >> SharedPreferences.Editor editorPrefs = prefs.edit(); >> editorPrefs.putBoolean("firstLaunch", false); >> editorPrefs.commit(); >> >> So far so good. Everything works as expected. However, I wanted to >> test its behavior when the preference file is removed. I removed the >> file '/data/data/com.example/shared_prefs/pref.xml' and relaunched the >> app within the emulator. To my surprise I found that my technique >> fails -- the variable 'isFirstTimeLaunch' will be false, even if I >> remove the preferences file.I repeated removing and launching the app >> many times and I see the same result every time. >> >> However, if I run the program from within Eclise IDE or if I do an >> 'adb install' from the shell, things work as expected.Obviously these >> methods clear the app data. Isn't simply removing the preference file >> same as removing data since my app doesn't use anything else? >> >> Am I missing something here? Can someone explain what's wrong with my >> program? >> >> Thanks >> Devi Prasad >> >> > > > > >
--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---