Skip to content

Commit

Permalink
make sure monitor service is running
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed Nov 3, 2017
1 parent 083d895 commit c8236b7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public class MonitorService extends Service {
BarometerMonitor mBaroMonitor = null;
AmbientLightMonitor mLightMonitor = null;

private boolean mIsRunning = false;
/**
* Last Event instances
*/
Expand Down Expand Up @@ -150,6 +151,7 @@ public void onDestroy() {
stopForeground(true);



}

/**
Expand Down Expand Up @@ -199,8 +201,16 @@ private void showNotification() {

}

public boolean isRunning ()
{
return mIsRunning = true;

}

private void startSensors ()
{
mIsRunning = true;

if (prefs.getAccelerometerSensitivity() != PreferenceManager.OFF) {
mAccelManager = new AccelerometerMonitor(this);
mBaroMonitor = new BarometerMonitor(this);
Expand All @@ -215,6 +225,8 @@ private void startSensors ()

private void stopSensors ()
{
mIsRunning = false;

if (prefs.getAccelerometerSensitivity() != PreferenceManager.OFF) {
mAccelManager.stop(this);
mBaroMonitor.stop(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public void onReceive(Context context, Intent intent) {
boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;

if (MonitorService.getInstance() != null) {
if (MonitorService.getInstance() != null
&& MonitorService.getInstance().isRunning()) {
MonitorService.getInstance().alert(EventTrigger.POWER, context.getString(R.string.status_charging) + isCharging + " USB:" + usbCharge + " AC:" + acCharge);
}
}
Expand Down

0 comments on commit c8236b7

Please sign in to comment.