I want to create a sort of session where the user logs in and for an amount of time he doesn't have to type his password everytime he opens the app.
i tried to do something like this , just for test : but if you have any ideas i'd really appreciate it , thanks. Again this is just a test to see if i can modify a stored value after some time.
public class MainActivity extends AppCompatActivity {
public SharedPreferences mPreferenceManager;
public SharedPreferences.Editor mEditor;
private static final int DURATION = 20000;
private long activatedAt = Long.MAX_VALUE;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView hello=(TextView) findViewById(R.id.hello);
Button but1=(Button) findViewById(R.id.button1);
but1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i=new Intent(MainActivity.this,configActivity.class);
startActivity(i);
}
});
SharedPreferences setting = getSharedPreferences("settings", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = setting.edit();
long activeFor=System.currentTimeMillis()-activatedAt;
if(activeFor>5000){
editor.clear();
Log.d("here-",">50000");
}else{
editor.putString("pseudo","hello");
editor.commit();
Log.d("here-","<50000");
}
hello.setText(setting.getString("pseudo",""));
}