Start foreground on create

Sometimes there is a significant delay between on create and on start command
This commit is contained in:
M66B 2019-07-30 08:46:38 +02:00
parent eaf3ea4a7c
commit 954c8db225
3 changed files with 8 additions and 7 deletions

View File

@ -36,11 +36,15 @@ public class ServiceExternal extends Service {
// adb shell am startservice -a eu.faircode.email.DISABLE
@Override
public void onCreate() {
super.onCreate();
startForeground(Helper.NOTIFICATION_EXTERNAL, getNotification().build());
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
try {
startForeground(Helper.NOTIFICATION_EXTERNAL, getNotification().build());
Log.i("Received intent=" + intent);
Log.logExtras(intent);

View File

@ -72,6 +72,7 @@ public class ServiceSend extends ServiceBase {
public void onCreate() {
Log.i("Service send create");
super.onCreate();
startForeground(Helper.NOTIFICATION_SEND, getNotificationService(null, null).build());
cowner = new TwoStateOwner(ServiceSend.this, "send");
final DB db = DB.getInstance(this);
@ -223,10 +224,7 @@ public class ServiceSend extends ServiceBase {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
startForeground(Helper.NOTIFICATION_SEND, getNotificationService(null, null).build());
super.onStartCommand(intent, flags, startId);
return START_STICKY;
}

View File

@ -119,6 +119,7 @@ public class ServiceSynchronize extends ServiceBase {
public void onCreate() {
Log.i("Service create version=" + BuildConfig.VERSION_NAME);
super.onCreate();
startForeground(Helper.NOTIFICATION_SYNCHRONIZE, getNotificationService(null).build());
// Listen for network changes
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
@ -251,8 +252,6 @@ public class ServiceSynchronize extends ServiceBase {
Log.i("Service command intent=" + intent + " action=" + action);
Log.logExtras(intent);
startForeground(Helper.NOTIFICATION_SYNCHRONIZE, getNotificationService(null).build());
super.onStartCommand(intent, flags, startId);
if (action != null)