mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Fix starting the download service in the background throw exception
This happens when the device screen is locked. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=198875192
This commit is contained in:
parent
6cfc7b7ebb
commit
536bd68294
1 changed files with 10 additions and 2 deletions
|
|
@ -95,8 +95,16 @@ public class SampleChooserActivity extends Activity
|
||||||
loaderTask.execute(uris);
|
loaderTask.execute(uris);
|
||||||
|
|
||||||
// Ping the download service in case it's not running (but should be).
|
// Ping the download service in case it's not running (but should be).
|
||||||
startService(
|
Intent serviceIntent =
|
||||||
new Intent(this, DemoDownloadService.class).setAction(DownloadService.ACTION_INIT));
|
new Intent(this, DemoDownloadService.class).setAction(DownloadService.ACTION_INIT);
|
||||||
|
// Starting the service in the foreground causes notification flicker if there is no scheduled
|
||||||
|
// action. Starting it in the background throws an exception if the app is in the background too
|
||||||
|
// (e.g. if device screen is locked).
|
||||||
|
try {
|
||||||
|
startService(serviceIntent);
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
startForegroundService(serviceIntent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue