Run start service on foreground

This commit is contained in:
M66B
2021-03-25 09:36:45 +01:00
parent a2f78423df
commit f7a85deeec
18 changed files with 263 additions and 114 deletions

View File

@@ -2023,7 +2023,16 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
prefs.edit().putInt("poll_interval", OPTIMIZE_POLL_INTERVAL).apply();
} else if (pollInterval <= 60 && account.poll_exempted) {
db.account().setAccountPollExempted(account.id, false);
ServiceSynchronize.eval(this, "Optimize=" + reason);
ApplicationEx.getMainHandler().post(new Runnable() {
@Override
public void run() {
try {
onEval(new Intent().putExtra("account", account.id));
} catch (Throwable ex) {
Log.e(ex);
}
}
});
}
}
@@ -2432,12 +2441,13 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
private static void start(Context context, Intent intent) {
if (isBackgroundService(context))
context.startService(intent);
else
else {
try {
ContextCompat.startForegroundService(context, intent);
} catch (Throwable ex) {
Log.e(ex);
}
}
}
private static boolean isBackgroundService(Context context) {