I'm trying to design a GCMHelper class. Essentially, the class is a singleton, and the Activity can request the singleton to setupGCM() as such.
GCMHelper.getInstance(MainActivity.this).setupGCM();
The setupGCM() method will just see if a GCM registration is necessary (e.g. app has no gcm, or app is updated needing a new gcm), and do nothing if a registration is not needed.
This is "ok" because my activity doesn't need to touch the GCM id value. Everything is handled in setupGCM() method of the singleton. setupGCM() happens in the background, so control goes right back to activity. No UI lag. GCM id generation happens fast, but I'm trying to account for the following error in the documentation.
public static final String ERROR_SERVICE_NOT_AVAILABLE
The device can't read the response, or there was a 500/503 from the server that can be retried later. The application should use exponential back off and retry.
So my setupGCM method will keep trying as of right now (5 times to be exact with a few seconds increasing between each delay between each retry). But what happens if the user presses back and calls finish() on said activity. Now the activity is finished, but the context is still saved with a singleton. This causes a memory leak no?
This would happen even if the GCMHelper wasn't a singleton. The reason it IS a singleton is so that the next time the activity gets created it can see if a regeneration retry is already in progress.
What happens if I pass it MainActivity.this.getApplicationContext() to the context needed for the singleton. Will that be better for the Activity because it will be allowed to be GC'd?