diff --git a/app/src/main/java/com/stevesoltys/backup/Backup.java b/app/src/main/java/com/stevesoltys/backup/Backup.java index 00c1c7c5..b4b0474c 100644 --- a/app/src/main/java/com/stevesoltys/backup/Backup.java +++ b/app/src/main/java/com/stevesoltys/backup/Backup.java @@ -1,9 +1,6 @@ package com.stevesoltys.backup; import android.app.Application; -import android.content.Intent; - -import com.stevesoltys.backup.transport.ConfigurableBackupTransportService; /** * @author Steve Soltys @@ -12,10 +9,4 @@ public class Backup extends Application { public static final int JOB_ID_BACKGROUND_BACKUP = 1; - @Override - public void onCreate() { - super.onCreate(); - - startForegroundService(new Intent(this, ConfigurableBackupTransportService.class)); - } } diff --git a/app/src/main/java/com/stevesoltys/backup/activity/MainActivityController.java b/app/src/main/java/com/stevesoltys/backup/activity/MainActivityController.java index 0c7d6c6a..f569d376 100644 --- a/app/src/main/java/com/stevesoltys/backup/activity/MainActivityController.java +++ b/app/src/main/java/com/stevesoltys/backup/activity/MainActivityController.java @@ -14,6 +14,7 @@ import android.widget.Toast; import com.stevesoltys.backup.activity.backup.CreateBackupActivity; import com.stevesoltys.backup.activity.restore.RestoreBackupActivity; import com.stevesoltys.backup.service.backup.BackupJobService; +import com.stevesoltys.backup.transport.ConfigurableBackupTransportService; import java.io.IOException; import java.text.SimpleDateFormat; @@ -57,6 +58,9 @@ public class MainActivityController { showChooseFolderActivity(parent, true); } else { try { + // ensure that backup service is started + parent.startService(new Intent(parent, ConfigurableBackupTransportService.class)); + Uri fileUri = createBackupFile(parent.getContentResolver(), folderUri); showCreateBackupActivity(parent, fileUri); diff --git a/app/src/main/java/com/stevesoltys/backup/service/backup/BackupJobService.java b/app/src/main/java/com/stevesoltys/backup/service/backup/BackupJobService.java index ab74da64..1bcc3998 100644 --- a/app/src/main/java/com/stevesoltys/backup/service/backup/BackupJobService.java +++ b/app/src/main/java/com/stevesoltys/backup/service/backup/BackupJobService.java @@ -4,6 +4,7 @@ import android.app.backup.BackupManager; import android.app.backup.IBackupManager; import android.app.job.JobParameters; import android.app.job.JobService; +import android.content.Intent; import android.net.Uri; import android.os.RemoteException; import android.util.Log; @@ -11,6 +12,7 @@ import android.util.Log; import com.google.android.collect.Sets; import com.stevesoltys.backup.service.PackageService; import com.stevesoltys.backup.service.TransportService; +import com.stevesoltys.backup.transport.ConfigurableBackupTransportService; import com.stevesoltys.backup.transport.component.provider.ContentProviderBackupConfiguration; import com.stevesoltys.backup.transport.component.provider.ContentProviderBackupConfigurationBuilder; @@ -44,6 +46,7 @@ public class BackupJobService extends JobService { @Override public boolean onStartJob(JobParameters params) { Log.i(TAG, "Triggering full backup"); + startService(new Intent(this, ConfigurableBackupTransportService.class)); try { LinkedList packages = new LinkedList<>(new PackageService().getEligiblePackages()); packages.removeAll(IGNORED_PACKAGES); 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 cbbd89ad..89d74e1c 100644 --- a/app/src/main/java/com/stevesoltys/backup/transport/ConfigurableBackupTransportService.java +++ b/app/src/main/java/com/stevesoltys/backup/transport/ConfigurableBackupTransportService.java @@ -1,16 +1,16 @@ package com.stevesoltys.backup.transport; -import android.app.Notification; import android.app.Service; import android.content.Intent; import android.os.IBinder; +import android.util.Log; /** * @author Steve Soltys */ public class ConfigurableBackupTransportService extends Service { - private static final int FOREGROUND_ID = 43594; + private static final String TAG = ConfigurableBackupTransportService.class.getName(); private static ConfigurableBackupTransport backupTransport = null; @@ -26,11 +26,17 @@ public class ConfigurableBackupTransportService extends Service { @Override public void onCreate() { super.onCreate(); - startForeground(FOREGROUND_ID, new Notification.Builder(this).build()); + Log.d(TAG, "Service created."); } @Override public IBinder onBind(Intent intent) { return getBackupTransport().getBinder(); } + + @Override + public void onDestroy() { + super.onDestroy(); + Log.d(TAG, "Service destroyed."); + } }