I want to show a message after the first launch of the app telling about the new features, each time a user installs a new version.
How do I do that?
Thanks in advance
I used this. It was posted by another stackoverflow member I don't recall who. Sorry. Call this code from onCreate()
// Show changelog
SharedPreferences prefs = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
PackageInfo pInfo;
try {
pInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_META_DATA);
if (prefs.getLong("lastRunVersionCode", 0) < pInfo.versionCode) {
showDialog(DIALOG_CHANGELOG);
SharedPreferences.Editor editor = prefs.edit();
editor.putLong("lastRunVersionCode", pInfo.versionCode);
editor.commit();
}
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Error reading versionCode");
e.printStackTrace();
}
Have an activity for this, that checks if a preference has the value of the current version. If so proceed to the next activity. Otherwise störe the current version in the preference, show the what's new screen and then on button press procees to the next activity
That's simple.
On the first start show an AlertDialog and create a record in SharedPreferences. Whatever - flag or a string, or somewhat.
The next time your application is started just check that you have this flag in preferences. If there is no one, then this is a first start and it's time to show a dialog =)
You have to save somewhere a value which you can check on each startup whether the app was already started. SharePreferences would be a option. Or within a database.
if the user clears application data in the device settings then this all gets reset.
Related
I am making an Android project. In that project i want a screen to appear only during the app installation and not every time we start the app. For eg. in whatsapp the page in which we put our name appears only during installation. I want exactly that type of a screen. I am fairly new to android programming so any help will be appreciated. Thanks! Cheers!
You can use the SharedPreferences to identify if it is the "First time" the app is launched.
Just use a Boolean variable ("app_first_time") and change its value to false after your task runs for the first time.
final String PREFS_NAME = "PrefsFile";
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
if (settings.getBoolean("app_first_time", true)) {
//here the app is being launched for first time, launch your screen
settings.edit().putBoolean("app_first_time", false).commit();
}
i'm making an app in android, it has more than one option in the menu, and the login information is needed to proceed in every option, so i want to make the user sign only once not each time he's choosing one of the options like the facebook application i have to sign in only once even when the application is running in the background it doesn't logout..
sry 4 the long explanation but i don't know even the keyword for searching about this issue..
can u please help me guys ?
Thank u
Once the user enter the login credential first time then use SharedPreferences and set the value to isLogged to 1.
Next time when user open the app then check this variable if this variable value is '1' then open the home activity.
SharedPreferences sharedPref = getSharedPreferences("data",MODE_PRIVATE);
int number = sharedPref.getInt("isLogged", 0);
if(number == 0) {
//Open the login activity and set this so that next it value is 1 then this conditin will be false.
SharedPreferences.Editor prefEditor = sharedPref.edit();
prefEditor.putInt("isLogged",1);
prefEditor.commit();
} else {
//Open this Home activity
}
I want to use this info to determine the most frequently used apps on my device.
I am also interested in finding out if there is a way to determine how much time I have spent using each app on my device.
It seems this info might be accessible only on "jailbroken" devices. I am hoping that is not the case.
Thanks much!
i think you can't do that for all apps.
instead , if you want to know how much times your app has been launched , try this :
on the splachscreen of your app ( or the first activity launched) , try to increment a number , and save it on the SharedPreferences :
SharedPreferences prefs = getSharedPreferences("prefs",Context.MODE_PRIVATE);
int counter = prefs.getInt("counter", -1);
if(counter == -1 ) {
//first launch of the app, init the counter
counter = 1;
}
else {
// increment the counter
counter++;
}
// update the value of the counter
SharedPreferences.Editor editor = prefs.edit();
editor.putInt("counter",counter);
editor.commit();
//then you can do what you want with your counter , send it to your back end via web service...etc
I am doing a project in which,i have to give the user a message at the time of installation only.After that the message should be hidden.Now whenever i run the program the message will be displayed.I want to avoid it. I want to do it programatically in android.Can anyone help to resolve this issue?
Thanks in Advance
You can save a flag into the app database or userPreferences and after displaying the message you can set the flag to false or 0 . Anytime the user starts the app you check that flag and see if you have to display it again or not...
Use SharedPreferences.
SharedPreferences settings = getSharedPreferences("MyPref", MODE_PRIVATE);
Editor edt = settings.edit();
edt.putBoolean("Accepted", true);
edt.commit();
boolean isTOSAccepted = settings.getBoolean("Accepted", false);
I am working on an application which requires me to create a log in screen. The way I have planned to do this is have 2 tabs log in, sign up and what I wanted to know is I want to be able to have a user sign up and if they choose remember password next time they load the app it should go straight to the main menu. Although selecting sign out in the main menu should load up the tabs with the log in information when they start the app again.
The question I have is how do I implement the remember me button so next time it skips the log in and how do I implement the sign out so next time the app loads the log in screen.
Thank you in advance! (",)
Sri
Throw the remembered answer into the SharedPreferences and read it when your activity starts and process it accordingly.
I would probably use Internal Storage to store the username/password for the remember me button.
When the app loads, first check if the user/pass is already saved. If so then direct to the tabs, if not then direct to the log in screen.
First Log In :
SharedPreferences sSession = PreferenceManager.getDefaultSharedPreferences(context);
Editor ePrefrences = sSession.edit();
ePrefrences.putString("id", "user id");
ePrefrences.putString("password", "user password");
ePrefrences.putBoolean("successfullylogin", true);
ePrefrences.commit();
Second Log In :
SharedPreferences sSession = PreferenceManager.getDefaultSharedPreferences(this);
if (sSession .getBoolean("successfullylogin", false)) {
//get user name and password
sUser = sSession.getString("id", "");
sPassword = sSession.getString("password", "");
//start activity
}
else {
//prepare for normal login
}