Continue Download in android even after the device is locked

Ganga picture Ganga · Jun 2, 2016 · Viewed 9.5k times · Source

How to continue download task even when after the device is locked (pressing the power button). I tried installing an app from the play store, and during its download i locked the device, but it still continues to download without any interruption and is visible on the lockscreen as shown in the screen shot below. How do we achieve this programmatically?

enter image description here

Answer

chessdork picture chessdork · Jun 2, 2016

If you want a task to continue running, even when your Activity is not active, you need to use a Service. https://developer.android.com/guide/components/services.html. The Play Store is probably using a Service to keep the download running in the background, and a Notification to show the status on the lock screen. https://developer.android.com/guide/topics/ui/notifiers/notifications.html