0

I am developing a Application which will create events in calendar. Events should get created only once when my application is installed and opened. I tried with using Shared preferences. But when i clear my app data, shared preferences were also getting cleared.

Please let me know how to do this.

anonymous
  • 483
  • 2
  • 8
  • 24
  • when you want to update the events? – balaji koduri Jan 21 '15 at 06:53
  • @balajikoduri I my creating events when my main activity is viewed. In my main activity i surrounded the code to create event with shared preferences check. But when i clear my app data, data stored in shared preferences were also getting cleared and again when i view my main activity events where creating again in calendar – anonymous Jan 21 '15 at 06:57
  • you have to handle the clear data event, check this link : http://stackoverflow.com/a/7424193/2633173 – balaji koduri Jan 21 '15 at 07:07

1 Answers1

1

Although Shared preferences is usually used for the use case like yours, but since you wants to be guarded against "Clear Data", You may create an empty file as an alternative.

You can check (before creating a Cal.event) if your file(whose exact name and location is only known to you) exist.

Obviously, there are many situations with this approach against which you need to protect.

1.what if user removes this file? 2.if you chose to save file on SD-card, what if sdcard is removed?

In case, if you do not want to rely on Device and data saved on device, and if your app can communicate with Server, then you can maintain this installation history information "online". Then, invoke a network call to query "installation history" info.

For this method to work, you also needs to track on which device and user, the installation was done previously.

AADProgramming
  • 6,077
  • 11
  • 38
  • 58
  • Yes,but more control can be attained by maintaining a synchronization of the application state with the our servers – nobalG Jan 21 '15 at 07:09
  • @nobalG: Agree!! Using Server, and then query to it about "installation history" is preferable! But Not sure if that back end Environment is available in Answer seeker's case. – AADProgramming Jan 21 '15 at 07:13
  • Just added that point in case if that infrastructure is present!! – AADProgramming Jan 21 '15 at 07:29