tags:

views:

94

answers:

6

Hi,

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?

+1  A: 

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)

Flash84x
This is a good idea, thanks. I can even track of the number of times this app was used.
Sana
+4  A: 

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.

Mayra
+1  A: 

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

fazo
A: 

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?

Sana
You can edit your original question and add updates to it. Read Stackoverflow FAQ. Also don't forget to mark an answer as accepted on with the tick on the left.
Pentium10
+2  A: 

Android has API to store preferences.

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

Pentium10
A: 

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.

Morrison Chang
Server calls in a bad network area(my test area :() will frustrate the user!Ok thanks.
Sana