Improved boot

This commit is contained in:
M66B
2019-02-28 07:55:08 +00:00
parent fe6fa7a2d5
commit d32b55d2c5
5 changed files with 136 additions and 118 deletions

View File

@@ -60,6 +60,8 @@ import androidx.lifecycle.Observer;
public class ServiceSend extends LifecycleService {
private int lastUnsent = 0;
private static boolean booted = false;
private static final int IDENTITY_ERROR_AFTER = 30; // minutes
@Override
@@ -413,6 +415,27 @@ public class ServiceSend extends LifecycleService {
}
}
static void boot(final Context context) {
if (!booted) {
booted = true;
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
DB db = DB.getInstance(context);
EntityFolder outbox = db.folder().getOutbox();
if (outbox != null && db.operation().getOperations(outbox.id).size() > 0)
start(context);
} catch (Throwable ex) {
Log.e(ex);
}
}
});
thread.start();
}
}
static void start(Context context) {
context.startService(new Intent(context, ServiceSend.class));
}