Two examples you could read into:
http://www.flurry.com
http://www.google.com/analytics/
These both are DataReporting services which offer APIs to export your data e.g. as JSON. The main aim is that your app sends usage statistics to external servers (where the data can be viewed by you).
Furthermore, you can also connect to those servers and retrieve the data back on your device.
UPDATE - LOCAL STORAGE
If you only want a local counter on the device that shows the user how often he visited the app, check out SharedPreferences.
SharedPreferences enables you to store data on your device and also retrieve that data again when you open or close the app.
UPDATE - GLOBAL - DATABASE
If you want just a "global" counter. Id recommend you create an SQL Database for that where you store the current visitor count and increment it each time the user visits and receive the current count on app startup to display it.
If you want to track the different users of your app that are currently using the app, you could generate an identical id for each user and store it in your SQL Database when the user first opens the app and increment the counter.
For that you will of course also need a table where the ids are stored.
When the user closes the app, you will need to connect to the database again and remove his id from the table and decrement the counter.
This could be a way of getting a unique ID for each user:
public class Installation {
private static String sID = null;
private static final String INSTALLATION = "INSTALLATION";
public synchronized static String id(Context context) {
if (sID == null) {
File installation = new File(context.getFilesDir(), INSTALLATION);
try {
if (!installation.exists())
writeInstallationFile(installation);
sID = readInstallationFile(installation);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return sID;
}
private static String readInstallationFile(File installation) throws IOException {
RandomAccessFile f = new RandomAccessFile(installation, "r");
byte[] bytes = new byte[(int) f.length()];
f.readFully(bytes);
f.close();
return new String(bytes);
}
private static void writeInstallationFile(File installation) throws IOException {
FileOutputStream out = new FileOutputStream(installation);
String id = UUID.randomUUID().toString();
out.write(id.getBytes());
out.close();
}
}
Taken from here: Android unique id