Eric MORAND
Eric MORAND

Reputation: 6783

Android Best Practices : Best way to check for Google account existence?

I've recently started developing for the Android platform and am currently praticing with an application that sync with Google Tasks. Right now, I'm not facing too much problem, technically speaking. But I meet a conceptual problem that I can't find a proper way to solve.

Let's say the user uses my application with a given Google account. He launch some activities, do some work...and then click the Home button. He then goes to the OS Settings and delete its Google accounts. Then he returns to my app, which then display the activity he was using when he did quit the app.

Since there is no more Google Accounts, my application should present the "Add Account" activity to allow him to choose or create a Google Account. And of course, if he tap on the back button at this point, he should be sent to the launcher and not to the previous activity from the back stack.

How would you deal with that kind of need?

I first thought that it was possible to be notified when my app was back to the foreground but it seems that Android always deals with activities, which would mean that I have to implement an "account checker" on all my activities ! Moreover, even if I implement this, how would I prevent the user from returning to the back stack and be instead redirected to the launcher when he taps the back button?

If some of you can give me some advices, some Best Practices, to deal with this, you would make my day.

PS : I just checked the Android 4 included GMail app and when I delete all my Google Accounts and then launch the app, I'm presented with the system "Add Google Account" activity and taping the back button send me to the launcher. That's exactly the behavior I'd like to implement. I suppose this app is not open-source, right?

Upvotes: 2

Views: 572

Answers (1)

snowCrabs
snowCrabs

Reputation: 785

onResume will be called when the activity comes to the foreground and onPause will be called when the activity is pushed to the back stack of activities.

You could always check the account status onResume. I would then recommend that you extend the activity class and make a BaseClass that has your google checker in it so every activity you want to have the check has it.

As far as the back button you can register a listener for the button press you can even ignore the back button if you are so inclined(not recommended but allowed by the sdk).

Upvotes: 1

Related Questions