Hi,
I am doing some Android application, and I need to determine if my Android application is used for the first time. So here, I will explain two ways how to solve this problem.
First way is to check if exists some empty file.
Okey, this way seems the most obvious, but there is better way to do this. You can check if Android application is used for the first time with SharedPreferences.
I am doing some Android application, and I need to determine if my Android application is used for the first time. So here, I will explain two ways how to solve this problem.
First way is to check if exists some empty file.
String path = Environment.getExternalStorageDirectory().getAbsolutePath() +
"/Android/data/myapplication/files/emptyfile.txt";
boolean exists = (new File(path)).exists();
if (!exists) {
//do something
}
else {
//do something
}Okey, this way seems the most obvious, but there is better way to do this. You can check if Android application is used for the first time with SharedPreferences.
final String PREFS_NAME = "MyPrefsFile";
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
if (settings.getBoolean("my_first_time", true)) {
//the app is being launched for first time, do something
// record the fact that the app has been started at least once
settings.edit().putBoolean("my_first_time", false).commit();
}















