How to determine if the app is being used for the first time?

51 views
Skip to first unread message

Hannah R

unread,
May 20, 2021, 11:52:19 AM5/20/21
to CodenameOne Discussions
Hi,

How can I find out when the app was launched the first time after installation? 
Thank you a lot. 

Javier Anton

unread,
May 20, 2021, 11:55:26 AM5/20/21
to codenameone...@googlegroups.com
You can use Preferences to write a small boolean value that is set to true after the first time the app is used

Updating an already installed app wont reset the flag as that re uses the app data folder



--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/c7b0a5b4-cfc9-48d8-85c6-7619272c6d2bn%40googlegroups.com.

Hannah R

unread,
May 20, 2021, 11:58:04 AM5/20/21
to CodenameOne Discussions
Thank you, Javier. 

I wondered if there are any other options because I use Preferences.clearAll() in some cases, as well as I wasn't sure about app updates etc. But I guess if there are no other ways or this is the best one, will do it. 

Ben Thacker

unread,
May 20, 2021, 12:02:21 PM5/20/21
to codenameone...@googlegroups.com
You could reset the flag immediately after the ClearAll.

Hannah R

unread,
May 20, 2021, 12:03:07 PM5/20/21
to CodenameOne Discussions

Yes, that what I was thinking. 

Javier Anton

unread,
May 20, 2021, 12:16:51 PM5/20/21
to codenameone...@googlegroups.com
Oh yes, just use the Storage class to write its own file instead of Preferences and then you won't have to worry about Prefs.clearAll
Preferences just uses a single file where it stores a dictionary, but you can write separate files and that will take care of it

Shai Almog

unread,
May 21, 2021, 12:58:51 AM5/21/21
to CodenameOne Discussions
Preferences clearAll is pretty destructive. I would suggest using it only in extreme cases.

Hannah R

unread,
May 24, 2021, 4:00:27 PM5/24/21
to CodenameOne Discussions
I noticed that Android 7 device (API 24) doesn't erase some of the preferences when the app is being reinstalled, unless I call clearAll() or manually choose "Clear Data" in the App Storage settings. 
This caused some bugs. 
Adding  android.allowBackup=false to the hints resolved this particular problem. 

Shai Almog

unread,
May 24, 2021, 10:11:00 PM5/24/21
to CodenameOne Discussions
You can delete individual files in storage one by one. Just avoid the preferences file name.
Reply all
Reply to author
Forward
0 new messages