Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get last opened date of an application in android?

Tags:

android

I want to get other applications last opened and used date in an android application...

Can anybody help on this?

like image 705
Muthu Avatar asked Dec 05 '25 12:12

Muthu


2 Answers

save the date every time you open your application into SharedPreferance but before saving it, just read the previous saved date, so now you save each time the user opens the app.

like image 83
Mohammad Ersan Avatar answered Dec 08 '25 05:12

Mohammad Ersan


Just save the last opened date if you want time then date and time both. use SharedPreference to store. The date and time will be stored in milliseconds. Then when you open your application you can retrieve that. Other alternative is to use SQLite Database. Store the last opened date in database. By single row you can work here by upgrading the database everytime you open the application.

It will work like blow example.

@Override
public void onResume() {
Editor e = PreferenceManager.getDefaultSharedPreferences(this).edit();
e.putString("last_activity", getClass().getSimpleName());
e.commit();

super.onResume();
}
like image 34
Varun Vishnoi Avatar answered Dec 08 '25 04:12

Varun Vishnoi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!