Skip to content
Permalink
Browse files

Foreground/Background service tweaks

- Catch a (not user visible?) stack trace when handling the stop button
  from the background.
- Launch using startForegroundService()... I'm not sure if this is
  important, given that we call startForeground() just afterward, but
  some users are "stopped mysteriously", and this might be related.
  • Loading branch information...
pmarks-net committed Sep 16, 2019
1 parent fa36ee7 commit e63fc0903e4fc840899450012646d0931602f105
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.pmarks.chromadoze"
android:versionCode="26"
android:versionName="4.0">
android:versionCode="27"
android:versionName="4.1">

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
@@ -24,7 +24,6 @@
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
@@ -37,7 +36,6 @@
import android.widget.TextView;

import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;

import java.util.ArrayList;
import java.util.Date;
@@ -300,7 +298,12 @@ private static Intent newStopIntent(Context ctx, int stopReasonId) {
}

public static void stopNow(Context ctx, int stopReasonId) {
ctx.startService(newStopIntent(ctx, stopReasonId));
try {
ctx.startService(newStopIntent(ctx, stopReasonId));
} catch (IllegalStateException e) {
// This can be triggered by running "adb shell input keyevent 86" when the app
// is not running. We ignore it, because in that case there's nothing to stop.
}
}

private static void saveStopReason(int stopReasonId) {
@@ -21,6 +21,8 @@
import android.content.Intent;
import android.content.SharedPreferences;

import androidx.core.content.ContextCompat;

import java.util.ArrayList;

public class UIState {
@@ -111,7 +113,7 @@ public void sendToService() {
getPhonon().writeIntent(intent);
intent.putExtra("volumeLimit", (float) getVolumeLimit() / MAX_VOLUME);
intent.putExtra("ignoreAudioFocus", mIgnoreAudioFocus);
mContext.startService(intent);
ContextCompat.startForegroundService(mContext, intent);
mDirty = false;
}

@@ -30,7 +30,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingBottom="10sp"
android:text="© 2018 Paul Marks" />
android:text="© 2019 Paul Marks" />

<TextView
android:layout_width="wrap_content"

0 comments on commit e63fc09

Please sign in to comment.
You can’t perform that action at this time.