- keyFirstTime is a string (see comment)
- you are PUTTING a value not getting a value
- You are using an assignment in an if statement
- You are comparing a STRING to a BOOLEAN
In Activity 1 you should have:
final String keyFirstTime = "keyFirstTime";
prefsEditor.putBoolean(keyFirstTime, false);
In Activity 2 you should have:
boolean firstTime = prefs.getBoolean(keyFirstTime, false); //you don't need the editor
if (firstTime) {
...
}
Please go here for a tutorial: https://developer.android.com/training/basics/data-storage/shared-preferences.html
EDIT Try doing this (stolen from here)
private static final String FIRST_RUN = "FIRST_RUN";
SharedPreferences prefs = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
prefs = getSharedPreferences(getApplicationContext().getPackageName(), MODE_PRIVATE);
}
@Override
protected void onResume() {
super.onResume();
if (prefs.getBoolean(FIRST_RUN, true)) {
prefs.edit().putBoolean(FIRST_RUN, false).commit();
//call relevant function for first run
} else {
//call relevant function for every other run
}
}