Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start services as foreground sooner #1099

Merged
merged 1 commit into from
Mar 16, 2019
Merged

Start services as foreground sooner #1099

merged 1 commit into from
Mar 16, 2019

Conversation

ahmedre
Copy link
Contributor

@ahmedre ahmedre commented Mar 15, 2019

Whenever a service is started as foreground, make the startForeground
call (along with showing the notification) one of the first things that
the service does.

Whenever a service is started as foreground, make the startForeground
call (along with showing the notification) one of the first things that
the service does.
@@ -357,6 +357,12 @@ public int onStartCommand(Intent intent, int flags, int startId) {
}

final String action = intent.getAction();
if (ACTION_PLAYBACK.equals(action)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just moving it up sooner - and start foreground even if we're already foreground (multiple calls are fine, but missing a call is asking for a crash).

@@ -233,6 +231,12 @@ private void sendNoOpMessage(int id) {

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// if it's a download, it wants to be a foreground service.
// quickly start as foreground before actually enqueueing the request.
if (ACTION_DOWNLOAD_URL.equals(intent.getAction())) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is actually a lot sooner than where it was happening before - before, handleOnStartCommand would process the message and then give it to the handler, which would eventually start foreground and show the notification. on some devices, this could take so long, so make it the first thing we do.


lastMaximum = -1;
lastProgress = -1;
showNotification(title, appContext.getString(R.string.downloading_message),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most important here is the flag for foreground being explicitly set to true.

@ahmedre ahmedre merged commit 5196c14 into quran:master Mar 16, 2019
@ahmedre ahmedre deleted the faster_foreground branch March 16, 2019 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant