0

I have made a chat application of my own. But in my chat application I have to login and logout again and again. I want to make it as What's App or any other chatting app ( i.e the user should login only once and rest all the time when there is internet connection available he/should getconnected to the application automatically and vice versa.

I have got no idea how to manage the same. I have searched it thoroughly, have found a clue regarding Application Class. But not enough so that I can use it in my application.

Please help me with a hyperlink regarding my requirement or guide me with a set of code so that I can start with.

Thanks

Gaurav Arora
  • 8,282
  • 21
  • 88
  • 143
  • 1
    You are looking for `Service` class. – wtsang02 Feb 04 '13 at 04:35
  • I just want to add single sign on feature for my app. I have made my app, but have to relogin and logout again and again. I want to remove this functionality and want to add SSO- single sign on approach- like what's app or other chat application in android – Gaurav Arora Feb 04 '13 at 04:36
  • 1
    "user should login only once and rest all the time when there is internet connection available..." You can only do this with `Service` regardless of other function mentioned. `Application` will die as soon as you finish your app. If you talking about in app only, just store user/pass in `SharedPreference`. – wtsang02 Feb 04 '13 at 04:40
  • @wtsang02, you mean a `Service` class is needed to receive messages in the background, right? Strictly speaking, single-sign-in doesn't require it. – Brian Attwell Feb 04 '13 at 05:03
  • yes @BrianAttwell as I mentioned both classes,they serve different purposes. – wtsang02 Feb 04 '13 at 05:08
  • Oh. Sorry @wtsang02, I didn't notice you wrote both the top and third comment. – Brian Attwell Feb 04 '13 at 05:09

1 Answers1

1

You do not need a Service class for single-sign-in! Use the SharedPreferences class.

You can persist the current user's password on the client device and use this to authenticate against the server every time the user opens the app.

Tech Lead on the Android Developer Relations team specifically recommends SharedPreferences: What is the most appropriate way to store user settings in Android application

If you want to receive messages in the background while your app isn't in the foreground, then you probably want to use Service class. You will probably want to use Google Cloud Messaging as well, which Google developed to help you with push notifications.

Community
  • 1
  • 1
Brian Attwell
  • 9,239
  • 2
  • 31
  • 26