I have been searching on the Internet about how to create a Session in an Android application. I found this and it certainly helped me in a part of my project.
At present, I have a similar situation where in I have a Login application that asks the user to enter the username and password. On click of the submit button I create and initialize my Session object.
The problem I am facing now is the fact that I want to know whether I can use this object in various activities apart from my Login application activity. I also want to know that if the Session object contain user credentials , can it be send via a web service and stored in a remote database?
Create a class that extends
Application(don’t forget to update your manifest file) and add to it the required fields (username, password and so on). This class will be available to all your activities. You can find a detailed explanation here.Later edit:
Let’s say you have a
Sessionclass withusernameas a field.Next, extend the
Application:Now, when you want to access the username, you can do it from any activity: