In my app i want to create a session for login and log out.
I dont have any idea how to work with session. Anybody help me by giving some sample example.
I think the session object should be a static object declared and initialized when your application starts running. I have met this problem and decided to put my session object in a utils class which contains mathods used by every activity in my app.
Here is a short example:
create a class for utils which will contain session object, Session is the class by which you implement your session object. It can contain, for example, userId, userName, etc.:
public class Utils {
public static Session mySessionObject = null;
}
When login button is pushed initialize your session object:
login.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Utils.mySessionObject = new Session();
//some extra initalization, for example setting userId
}
});
On logout you can destroy your session object.
Here is a link telling more about sessions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With