Automatically start transport service when application launches

This commit is contained in:
Steve Soltys 2018-11-11 21:00:00 -05:00
parent 2fa09be854
commit cc4b629a89
3 changed files with 31 additions and 8 deletions

View file

@ -10,6 +10,7 @@
android:targetSdkVersion="26"/> android:targetSdkVersion="26"/>
<application <application
android:name=".Backup"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme" android:theme="@style/AppTheme"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"

View file

@ -0,0 +1,21 @@
package com.stevesoltys.backup;
import android.app.Application;
import android.content.Intent;
import com.stevesoltys.backup.transport.ConfigurableBackupTransportService;
/**
* @author Steve Soltys
*/
public class Backup extends Application {
@Override
public void onCreate() {
startService(new Intent(this, ConfigurableBackupTransportService.class));
}
@Override
public void onTerminate() {
stopService(new Intent(this, ConfigurableBackupTransportService.class));
}
}

View file

@ -9,19 +9,20 @@ import android.os.IBinder;
*/ */
public class ConfigurableBackupTransportService extends Service { public class ConfigurableBackupTransportService extends Service {
// TODO: Make this field non-static and communicate with this service correctly. private static ConfigurableBackupTransport backupTransport = null;
private static ConfigurableBackupTransport backupTransport;
public ConfigurableBackupTransportService() { public static ConfigurableBackupTransport getBackupTransport() {
return backupTransport;
}
public void onCreate() {
if (backupTransport == null) {
backupTransport = new ConfigurableBackupTransport(); backupTransport = new ConfigurableBackupTransport();
} }
}
@Override @Override
public IBinder onBind(Intent intent) { public IBinder onBind(Intent intent) {
return backupTransport.getBinder(); return backupTransport.getBinder();
} }
public static ConfigurableBackupTransport getBackupTransport() {
return backupTransport;
}
} }