1

I can set a boolean flag in SharedPreferences to mark if the app is launched for the first time by the user. But the problem is: SharedPreferences can be cleared from Settings by the user, and some utility apps also ask user to clear app data when disk is almost full. My app will send is_new_user to server side to calculate some stats, so whether the flag is accurate is very important.

Is there any way I can write per-app data that cannot be cleared by user? If this is not possible, how can I make sure the is_new_user as accurate as possible?

NeoWang
  • 17,361
  • 24
  • 78
  • 126
  • I really do think this is possible. "Clear data" means "remove all your propertites" – Vyacheslav Jun 23 '16 at 07:51
  • Possible duplicate of [Is it possible to block Shared Preferences to avoid being deleted?](http://stackoverflow.com/questions/11926482/is-it-possible-to-block-shared-preferences-to-avoid-being-deleted) – Luca Nicoletti Jun 23 '16 at 07:52
  • not at all good practise.. u shud have user mechanism to check what is the user status – Sush Jun 23 '16 at 07:54
  • @sush You mean some some server side API like `is_device_id_new`? – NeoWang Jun 23 '16 at 07:56
  • yes exactly.. server data, which u can depend on.. so the things comes up like sign or registration. – Sush Jun 23 '16 at 07:58

3 Answers3

3

Is there any way I can write per-app data that cannot be cleared by user?

Yes but you shouldn't use it since it will confuse users. Confused users are not happy users.

how can I make sure the is_new_user as accurate as possible?

You might reconsider your logic and treat a user as a new user if he wipes the app data. It's pretty much the same as user getting a 2nd device and installing the app there.

Otherwise you can read through Is there a unique Android device ID? to get some inspiration for otherwise identifying 'new' installs.

Community
  • 1
  • 1
Tim
  • 41,901
  • 18
  • 127
  • 145
1

You can not relay on SharedPreferences. User can delete the app or install in another device. If it's critical you can save information about device id with app on your server. But it's not the better solution for different devices and device id can be changed or not exist. Another option is to create server site and ask user to login. Also you can save information that user already installed app before in google drive by using device's google account.

Edited: One more thing is Data backup

thealeksandr
  • 1,686
  • 12
  • 17
  • I am not worried if the user uninstall the app, I can consider the user new in that case. But now there are house-keeping utility apps that remind users to 'clean garbage', which clears all app data. I am just not sure what percentage of user base are effected. – NeoWang Jun 23 '16 at 08:08
  • Maybe you can try to use Data backup. I added a link in response – thealeksandr Jun 23 '16 at 08:13
1

A safe approach is to use HTTP post to archive such user's information to remote server.

You might consider using:

and using restful services to update a user's info such as if it is the first time he/she logins.

David
  • 15,894
  • 22
  • 55
  • 66