Is there an equivalent http session for an android app?

Is there a way to define something like a “session” for an Android app?
I have an application that launches several actions, and the user moves from activity to activity, etc.
Of course, you can switch to another application, make a phone call, stop using the application because it is busy, so the application is in the background, etc.
Is there a simple and meaningful way to define something like one session in all these different cases? So that we can find out when a new session begins and maybe some data is stored for each session?

+6
source share
2 answers

You can use SharedPreferences for this .

SharedPreferences wmbPreference1,wmbPreference2; SharedPreferences.Editor editor; //wmbPreference1 for Shared Prefs that lasts forever wmbPreference1 = PreferenceManager.getDefaultSharedPreferences(this); //wmbPreference2 for Shared Prefs that lasts only just once each time program is running wmbPreference2 =getApplicationContext().getSharedPreferences("MYKEY",Activity.MODE_PRIVATE); 

To save values

 SharedPreferences.Editor editor = wmbPreference1.edit(); editor.putString("MYKEY", "12345"); editor.commit(); 

You can get values like

 String Phonenumber = wmbPreference1.getString("MYKEY", ""); 

where MYKEY is the keyname with which you can determine the value.

+7
source

Unfortunately, the developer must determine what a “session” is in Android. So how can your activity be highlighted for a phone call in a minute, and then return to the foreground - is it part of the same session or two sessions? How about a 20 minute gap? You can keep the timestamp, but you are responsible for the "expiration" and the implementation of the appropriate behavior.

0
source

All Articles