Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store Android in-app purchases in SharedPreferences

Is it okay to store user in-app purchases in SharedPreferences? Moreover will SharedPreferences (which are saved to user's Google account, if I'm not wrong) will be the same for the app among all user's devices, which use same Google account?

like image 879
gs_vlad Avatar asked Feb 01 '26 04:02

gs_vlad


2 Answers

No, you shouldn't. If the user deletes the app data via the settings, this will also delete the SharedPreferences.

Use the API, to query the in-app purchases from the user, which is documented here.

like image 50
Julian Schmuckli Avatar answered Feb 02 '26 20:02

Julian Schmuckli


Julian is right, you should always query for the purchases, in onResume() for example.

If you did want to store the product id or part of the receipt in SharedPrefs just make sure to use Context.MODE_PRIVATE and I wouldn't store anything like purchaseToken or orderId.

like image 33
mutable2112 Avatar answered Feb 02 '26 20:02

mutable2112