How did IntentService start with BroadcastReceiver to instantiate Application class?
I am writing code that can transfer some data stored on a device to a network server when the C2DM app / app registration token changes.
This ultimately happens with the broadcast receiver (specifically the receiver called as a result of receiving the Google C2DM registration token)
@Override
public void onRegistered(Context context, String registrationId) throws IOException {
Log.d(TAG, "registrationId: " + registrationId);
Intent selectIntent = new Intent(this, AlertMigrationService.class);
this.startService(selectIntent);
}
(Note: My application uses a custom application class that extends the regular application class.)
I think technically this receiver could be called when my app is in the background (or not running) - so what happens when my intent service starts? Does this terminate my application and instantiate the Application class?
Is it safe (or even a good idea) for me to call static methods on my app class from an IntentService? (These static methods have return objects initialized in Application.onCreate)
source to share
When the IntentService starts, it will instantiate your Application class if your application is not already running. If your application is active, you will be able to access the modified application objects as they are. But if your application was killed and then the br service starts the service, a new instance of the entire application is created. Static methods don't give you the values ββyou want at the time. Store data somewhere and don't depend on the application lifecycle - that's what I suggest.
source to share