Make transport service start in foreground to resolve #13

This commit is contained in:
Steve Soltys 2018-12-15 03:30:29 -05:00
parent 98297537df
commit 7c3bff31f0
2 changed files with 15 additions and 9 deletions

View file

@ -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));
}
}

View file

@ -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();
}
}