Start intent service and close app

2019-08-09 09:50发布

问题:

I'm implementing GCM in my app and I start the RegistrationIntentService in the main activity. What happens if I close the app before the intent finishes?

The service takes a few seconds and I need the registration finishes despite the user has closed the app.

This work this way or I have to do something more?

Thanks!

回答1:

Unless the system suddenly kills the application process, the intent will finish, because as a user you don't have direct control over when the app is actually closed (meaning, the process finished). When you "close" the app, you just put the activity in the background and the system will probably shut the process down some time later (see this thread).

I have to do something more?

So no, you should be fine with the standard IntentService - in normal cases it will finish even if the user "closes" the app, and in the case of system deliberately killing your process, there is nothing you can do about it anyway.