Sana
Sana

Reputation: 9915

How do I know that an Android app has been loaded for the first time?

How do I figure out, if an app is loaded for the first time after it has been downloaded. I mean when the app is first bought/downloaded from market, how will I figure it that this is the first time(never has been run on this phone) this is going to run hence I can throw up some registration activity?


yeah, I thought of declaring a table which is checked to see if it has any rows. If there were rows then this was because it had been loaded and we inserted a row.

But I want to avoid this, is their any API which can tell me that the user had used this app before on this phone?

Upvotes: 0

Views: 1102

Answers (5)

Morrison Chang
Morrison Chang

Reputation: 12121

I don't know of any Android Market API that will tell you if the user downloaded/used the app before.

I think that you'll have to do it yourself which gives you two choices to persist data across an app uninstall/reinstall cycle:

(1) save a file on the SD card an check that to see if the app was installed before or

(2) contact a server with some user specific info to check if it was downloaded/used before.

The problem with the SD card method is that its not effective if the user erases the file or switches SD cards.

For the server model, you'll need to have a server to record some piece of information like user id or device id or some mix.

Upvotes: 0

Pentium10
Pentium10

Reputation: 207828

Android has API to store preferences.

You can store a flag in SharedPreferences, read about shared preferences

Upvotes: 4

fazo
fazo

Reputation: 1827

every application has it's own directory for data (/data/data/).

just write an empty file there and check for it every time you start an application

Upvotes: 1

Cheryl Simon
Cheryl Simon

Reputation: 46844

You can have a flag that you track, i.e. isFirstTime. Have a check in your main activity:

if(isFirstTime)
  // do registration

isFirstTime = false;

You can save the value in between executions as a shared preference. See Data Storage documentation for details on how to do that.

Upvotes: 3

Chris Wagner
Chris Wagner

Reputation: 20993

Write a property somewhere that persists on the first load and check for that on every load, if it is there then you know that it has already been loaded once. Or you might even just make it a load counter and maybe you could use that information as a statistic (report back some where)

Upvotes: 1

Related Questions