Skip to content

Commit

Permalink
Merge pull request ekasetiawans#336 from hasanm08/patch-1
Browse files Browse the repository at this point in the history
Service already running, using existing service
  • Loading branch information
ekasetiawans authored Aug 1, 2023
2 parents 7afbeaf + f8d4a49 commit 83bc49c
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@ public static void remove(Context context) {
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(ACTION_RESPAWN)){
final Config config = new Config(context);
if (!config.isManuallyStopped()) {
var isRunning = false
val manager = context.getSystemService(Context.ACTIVITY_SERVICE) as am
for (service in manager.getRunningServices(Int.MAX_VALUE)) {
if (BackgroundService::class.java.name == service.service.className) {
isRunning = true
}
}
if (!config.isManuallyStopped() && !isRunning) {
if (config.isForeground()) {
ContextCompat.startForegroundService(context, new Intent(context, BackgroundService.class));
} else {
Expand Down

0 comments on commit 83bc49c

Please sign in to comment.