UrielUVD
UrielUVD

Reputation: 482

GCM Registration Intent Service (Conditions and Update)

I followed the GCM quickstart tutorial and its working fine, but i have a few questions that related to the behavior of the service itself

Once the GooglePlayServieces connection results as success:

Intent intent = new Intent(this, RegistrationIntentService.class);
        startService(intent);

The Google documentation says that:

You should store a boolean that indicates whether the generated token has been sent to your server.

So, I stored it in my preferences so I know if my the token is in my server, but here are my questions.

  1. Is the service (not my server post implementation) called each time my app runs his MainActivity?
  2. If it does, how much impact have in the performance of network.
  3. Do i need another logic to manage if the service is called or not?
  4. When onTokenRefresh() I obviously need to send the token to my server again, so, is my duty to store the old token in my preferences to know which one to replace in my server or is stored in other place before it is refreshed?

Upvotes: 0

Views: 690

Answers (1)

reidisaki
reidisaki

Reputation: 1524

Is the service (not my server post implementation) called each time my app runs his MainActivity?

If it's in your onCreate() once per lifetime off app opened, if its onResume() every time the app comes in the foreground

If it does, how much impact have in the performance of network.

It's done on a seperate thread so it shouldn't be a problem, as it just sends a ping

Do i need another logic to manage if the service is called or not?

You would use some flag that you save in sharedPref to know if the service has been called before.

When onTokenRefresh() I obviously need to send the token to my server again, so, is my duty to store the old token in my preferences to know which one to replace in my server or is stored in other place before it is refreshed?

If you're refreshing a new token, i dont think you need to keep the outdated token, simply overwrite it with the new one you requested.

Upvotes: 2

Related Questions