Reputation: 13941
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.
Upvotes: 0
Views: 71
Reputation: 83577
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.
Upvotes: 1