give some time to service to start in UploadQueue

This commit is contained in:
Milos Kozak 2017-04-14 16:00:21 +02:00
parent a5d10708e6
commit 7aa2aa4d24

View file

@ -40,66 +40,78 @@ public class UploadQueue {
if (NSClientService.handler == null) { if (NSClientService.handler == null) {
Context context = MainApp.instance(); Context context = MainApp.instance();
context.startService(new Intent(context, NSClientService.class)); context.startService(new Intent(context, NSClientService.class));
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
}
} }
} }
public static void add(final DbRequest dbr) { public static void add(final DbRequest dbr) {
startService(); startService();
NSClientService.handler.post(new Runnable() { if (NSClientService.handler != null) {
@Override NSClientService.handler.post(new Runnable() {
public void run() { @Override
log.debug("QUEUE adding: " + dbr.data); public void run() {
MainApp.getDbHelper().create(dbr); log.debug("QUEUE adding: " + dbr.data);
NSClientInternalPlugin plugin = (NSClientInternalPlugin) MainApp.getSpecificPlugin(NSClientInternalPlugin.class); MainApp.getDbHelper().create(dbr);
if (plugin != null) { NSClientInternalPlugin plugin = (NSClientInternalPlugin) MainApp.getSpecificPlugin(NSClientInternalPlugin.class);
plugin.resend("newdata"); if (plugin != null) {
plugin.resend("newdata");
}
} }
} });
}); }
} }
public static void clearQueue() { public static void clearQueue() {
startService(); startService();
NSClientService.handler.post(new Runnable() { if (NSClientService.handler != null) {
@Override NSClientService.handler.post(new Runnable() {
public void run() { @Override
log.debug("QUEUE ClearQueue"); public void run() {
MainApp.getDbHelper().deleteAllDbRequests(); log.debug("QUEUE ClearQueue");
log.debug(status()); MainApp.getDbHelper().deleteAllDbRequests();
} log.debug(status());
}); }
});
}
} }
public static void removeID(final JSONObject record) { public static void removeID(final JSONObject record) {
startService(); startService();
NSClientService.handler.post(new Runnable() { if (NSClientService.handler != null) {
@Override NSClientService.handler.post(new Runnable() {
public void run() { @Override
try { public void run() {
String id; try {
if (record.has("NSCLIENT_ID")) { String id;
id = record.getString("NSCLIENT_ID"); if (record.has("NSCLIENT_ID")) {
} else { id = record.getString("NSCLIENT_ID");
return; } else {
return;
}
if (MainApp.getDbHelper().deleteDbRequest(id) == 1) {
log.debug("Removed item from UploadQueue. " + UploadQueue.status());
}
} catch (JSONException e) {
e.printStackTrace();
} }
if (MainApp.getDbHelper().deleteDbRequest(id) == 1) {
log.debug("Removed item from UploadQueue. " + UploadQueue.status());
}
} catch (JSONException e) {
e.printStackTrace();
} }
} });
}); }
} }
public static void removeID(final String action, final String _id) { public static void removeID(final String action, final String _id) {
startService(); startService();
NSClientService.handler.post(new Runnable() { if (NSClientService.handler != null) {
@Override NSClientService.handler.post(new Runnable() {
public void run() { @Override
MainApp.getDbHelper().deleteDbRequestbyMongoId(action, _id); public void run() {
} MainApp.getDbHelper().deleteDbRequestbyMongoId(action, _id);
}); }
});
}
} }
public String textList() { public String textList() {