Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android apps login design pattern

Is there any design pattern for creating an application with user login in Android.

My question is:

  • Where do we keep the login session for user that wants to stay logged id in Android apps?
  • Should there be a RootActivity that first checks whether user is logged in, if yes then redirect to HomeActivity otherwise redirect to LoginActivity? Or is there a better way to do this?

Any help or even links to documents on this topic is greatly appreciated.

like image 708
Joshua Partogi Avatar asked May 22 '11 14:05

Joshua Partogi


1 Answers

Where do we keep the login session for user that wants to stay logged id in Android apps?

Static data. Have some sort of singleton that represents the login session. When the process is terminated due to inactivity, the user will need to log in again.

Should there be a RootActivity that first checks whether user is logged in, if yes then redirect to HomeActivity otherwise redirect to LoginActivity?

If you have to lazy-create the singleton, or otherwise determine that the user is not logged in, redirect the user to a login activity. You will need to do this from every activity (e.g., in onResume()), since any activity can be an entry point into your app (e.g., from the recent tasks list).

like image 119
CommonsWare Avatar answered Oct 18 '22 15:10

CommonsWare