According to the documentation, settings stored with the setPreferenceForKey() method are lost during reinstalls or updates:
How can I store settings so that they will not be deleted when updating the widget? It's pretty annoying for widgets that offer a lot of customizations which you'd have to reconfigure everytime you install an update.The preference value for the key is stored persistently, so if the widget or device is restarted, the value is retained. However, the values stored by a widget are removed when a widget is uninstalled from the device. This includes the case when a widget is reinstalled; where the old widget is uninstalled, the new widget is installed.
According to this thread, cookies don't work properly.