java - Best way to retrieve logged user in app -


i want retrieve current logged user in many places in android app. best way?

  1. save in static variable in user class , retrieve user.getcurrentuser()
  2. get dao or repository usersrepository.getcurrentuser()

or there better way?

thanks.

in web application use standard way: request.getremoteuser()

if need have additional information user store in session:

session.setattribute("user", userobject); 

if using kind of application (for example mobile application) , 1 user per time can logged can use singleton store information of user:

user user = user.getinstance();  user.setname("blabla");    // store information  user.getname();            // information 

Comments

Popular posts from this blog

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -