0

Im learning Android and writing my first big application. It is client-server app and it uses Google login mechanism and will use Facebook login in future.

I wrote fundamental parts of app, like "Login with Google", connection with web service, few Activities that do something.

Now I have problem: how to put everything together?

Where should I store "application state", like current user e-mail or information if he is logged in or not? Now such data is inside "ActivityGoogleLogin" class which is destroyed after user logs in.

Another problem - lets say I have something like "MyHttpClient" object and I want to access it from every Activity. How to deal with this?

In C# (which is my background) I just create static class that holds my application state and it's easy to access it from everywhere.

I know that in Java something like "singleton" exists, but I don't know how to use it. It seems to be more complicated than C# static class where I don't even have to write accessors and I don't have to initialize it.

divibisan
  • 11,659
  • 11
  • 40
  • 58
Kamil
  • 13,363
  • 24
  • 88
  • 183

1 Answers1

1

Another problem - lets say I have something like "MyHttpClient" object and I want to access it from every Activity.

If every Activity needs a HTTP connection, they should each create their own instance of MyHttpClient rather than trying to share the same object between different activities.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268