diff --git a/app/src/main/java/com/stevesoltys/backup/Backup.java b/app/src/main/java/com/stevesoltys/backup/Backup.java index b79f96d3..d8989f78 100644 --- a/app/src/main/java/com/stevesoltys/backup/Backup.java +++ b/app/src/main/java/com/stevesoltys/backup/Backup.java @@ -11,11 +11,8 @@ public class Backup extends Application { @Override public void onCreate() { - startService(new Intent(this, ConfigurableBackupTransportService.class)); - } + super.onCreate(); - @Override - public void onTerminate() { - stopService(new Intent(this, ConfigurableBackupTransportService.class)); + startForegroundService(new Intent(this, ConfigurableBackupTransportService.class)); } } diff --git a/app/src/main/java/com/stevesoltys/backup/transport/ConfigurableBackupTransportService.java b/app/src/main/java/com/stevesoltys/backup/transport/ConfigurableBackupTransportService.java index aff9f1fb..e50db90a 100644 --- a/app/src/main/java/com/stevesoltys/backup/transport/ConfigurableBackupTransportService.java +++ b/app/src/main/java/com/stevesoltys/backup/transport/ConfigurableBackupTransportService.java @@ -1,5 +1,6 @@ package com.stevesoltys.backup.transport; +import android.app.Notification; import android.app.Service; import android.content.Intent; import android.os.IBinder; @@ -9,20 +10,28 @@ import android.os.IBinder; */ public class ConfigurableBackupTransportService extends Service { + private static final int FOREGROUND_ID = 43594; + private static ConfigurableBackupTransport backupTransport = null; public static ConfigurableBackupTransport getBackupTransport() { - return backupTransport; - } - public void onCreate() { if (backupTransport == null) { backupTransport = new ConfigurableBackupTransport(); } + + return backupTransport; + } + + @Override + public void onCreate() { + super.onCreate(); + + startForeground(FOREGROUND_ID, new Notification.Builder(this).build()); } @Override public IBinder onBind(Intent intent) { - return backupTransport.getBinder(); + return getBackupTransport().getBinder(); } }