Skip to content

Commit

Permalink
Catch exceptions raised when starting foreground service on Android
Browse files Browse the repository at this point in the history
HaylLtd#199

If an exception is raised when starting the foreground service this causes the app to crash.

One cause of exceptions can be if the user revokes the location or notification permissions whilst the foreground service is running.
  • Loading branch information
ibcomputing committed Oct 3, 2024
1 parent ff5d3f7 commit 096d9a2
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,13 @@ public void startForeground() {
mProvider.onCommand(LocationProvider.CMD_SWITCH_MODE,
LocationProvider.FOREGROUND_MODE);
}
super.startForeground(NOTIFICATION_ID, notification);
mIsInForeground = true;
try{
super.startForeground(NOTIFICATION_ID, notification);
mIsInForeground = true;
}catch(Exception e){
mIsInForeground = false;
logger.error("startForeground: exception", e);
}
}
}

Expand Down

0 comments on commit 096d9a2

Please sign in to comment.