Automatically start transport service when application launches
This commit is contained in:
parent
2fa09be854
commit
cc4b629a89
3 changed files with 31 additions and 8 deletions
|
@ -10,6 +10,7 @@
|
|||
android:targetSdkVersion="26"/>
|
||||
|
||||
<application
|
||||
android:name=".Backup"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
|
|
21
app/src/main/java/com/stevesoltys/backup/Backup.java
Normal file
21
app/src/main/java/com/stevesoltys/backup/Backup.java
Normal 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));
|
||||
}
|
||||
}
|
|
@ -9,19 +9,20 @@ import android.os.IBinder;
|
|||
*/
|
||||
public class ConfigurableBackupTransportService extends Service {
|
||||
|
||||
// TODO: Make this field non-static and communicate with this service correctly.
|
||||
private static ConfigurableBackupTransport backupTransport;
|
||||
private static ConfigurableBackupTransport backupTransport = null;
|
||||
|
||||
public ConfigurableBackupTransportService() {
|
||||
public static ConfigurableBackupTransport getBackupTransport() {
|
||||
return backupTransport;
|
||||
}
|
||||
|
||||
public void onCreate() {
|
||||
if (backupTransport == null) {
|
||||
backupTransport = new ConfigurableBackupTransport();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return backupTransport.getBinder();
|
||||
}
|
||||
|
||||
public static ConfigurableBackupTransport getBackupTransport() {
|
||||
return backupTransport;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue