Update broadcast receivers to work around background execution limits in Android O
minSdkVersion 21
targetSdkVersion 26
- versionCode 159
+ versionCode 160
versionName "3.6.2"
resConfigs "en", "ja", "ru", "de"
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
+import android.os.Handler;
import com.farmerbb.taskbar.activity.DummyActivity;
import com.farmerbb.taskbar.service.DashboardService;
context.startActivity(intent2);
}
- context.startService(new Intent(context, TaskbarService.class));
- context.startService(new Intent(context, StartMenuService.class));
- context.startService(new Intent(context, DashboardService.class));
+ new Handler().postDelayed(() -> {
+ context.startService(new Intent(context, TaskbarService.class));
+ context.startService(new Intent(context, StartMenuService.class));
+ context.startService(new Intent(context, DashboardService.class));
+ }, Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? 0 : 100);
}
- context.startService(new Intent(context, NotificationService.class));
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+ context.startForegroundService(new Intent(context, NotificationService.class));
+ else
+ context.startService(new Intent(context, NotificationService.class));
} else {
editor.putBoolean("taskbar_active", U.isServiceRunning(context, NotificationService.class));
editor.apply();
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
+import android.os.Handler;
import com.farmerbb.taskbar.activity.DummyActivity;
import com.farmerbb.taskbar.service.DashboardService;
context.startActivity(intent2);
}
- context.startService(new Intent(context, TaskbarService.class));
- context.startService(new Intent(context, StartMenuService.class));
- context.startService(new Intent(context, DashboardService.class));
+ new Handler().postDelayed(() -> {
+ context.startService(new Intent(context, TaskbarService.class));
+ context.startService(new Intent(context, StartMenuService.class));
+ context.startService(new Intent(context, DashboardService.class));
+ }, Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? 0 : 100);
}
- if(pref.getBoolean("taskbar_active", false))
- context.startService(new Intent(context, NotificationService.class));
+ if(pref.getBoolean("taskbar_active", false)) {
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+ context.startForegroundService(new Intent(context, NotificationService.class));
+ else
+ context.startService(new Intent(context, NotificationService.class));
+ }
}
}
}
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
+import android.os.Handler;
import android.support.v4.content.LocalBroadcastManager;
import com.farmerbb.taskbar.activity.DummyActivity;
context.startActivity(intent2);
}
- context.startService(taskbarIntent);
- context.startService(startMenuIntent);
- context.startService(dashboardIntent);
- context.startService(notificationIntent);
+ new Handler().postDelayed(() -> {
+ context.startService(taskbarIntent);
+ context.startService(startMenuIntent);
+ context.startService(dashboardIntent);
+ }, Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? 0 : 100);
+
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+ context.startForegroundService(notificationIntent);
+ else
+ context.startService(notificationIntent);
} else {
pref.edit().putBoolean("is_hidden", true).apply();
LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.taskbar.START_MENU_DISAPPEARING"));
}
- context.startService(notificationIntent);
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+ context.startForegroundService(notificationIntent);
+ else
+ context.startService(notificationIntent);
+
}
}
}
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
+import android.os.Handler;
import com.farmerbb.taskbar.activity.DummyActivity;
import com.farmerbb.taskbar.service.DashboardService;
context.startActivity(intent2);
}
- context.startService(new Intent(context, TaskbarService.class));
- context.startService(new Intent(context, StartMenuService.class));
- context.startService(new Intent(context, DashboardService.class));
- context.startService(new Intent(context, NotificationService.class));
+ new Handler().postDelayed(() -> {
+ context.startService(new Intent(context, TaskbarService.class));
+ context.startService(new Intent(context, StartMenuService.class));
+ context.startService(new Intent(context, DashboardService.class));
+ }, Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? 0 : 100);
+
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+ context.startForegroundService(new Intent(context, NotificationService.class));
+ else
+ context.startService(new Intent(context, NotificationService.class));
}
}
}
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.os.Build;
import android.support.v4.content.LocalBroadcastManager;
import com.farmerbb.taskbar.R;
pref.edit().putBoolean("freeform_hack", false).apply();
context.stopService(notificationIntent);
- context.startService(notificationIntent);
+
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+ context.startForegroundService(notificationIntent);
+ else
+ context.startService(notificationIntent);
LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.taskbar.FINISH_FREEFORM_ACTIVITY"));
LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.taskbar.UPDATE_FREEFORM_CHECKBOX"));
intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent2);
- context.startService(notificationIntent);
+
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+ context.startForegroundService(notificationIntent);
+ else
+ context.startService(notificationIntent);
LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.taskbar.UPDATE_FREEFORM_CHECKBOX"));
} else