0

My application has a non-sticky service running, whenever I close the app from the task manager by swiping it, it also kills my service instantly. I am facing this issue only in Oppo phones.

Dimitar
  • 4,402
  • 4
  • 31
  • 47
Adeel Turk
  • 897
  • 8
  • 23

2 Answers2

1

On the Oppo F1 you need to add COL Reminder to the "Startup Manager" to allow running in the background.

Go to "Security Center". Click "Privacy Permissions" Then "Startup manager" And allow "COL Reminder" to run in the background.


If it is still not working please check this steps:

Go to settings > Battery and Storage > Battery Manager > Tap on "Power consumption details" > Optimize for excessive power consumption. Now uncheck all the apps you are facing issues with. enter image description here

Nirav Joshi
  • 1,713
  • 15
  • 28
0

Many smartphones like Xiamoi, Oppo, Vivo kills background services even if it is running with flag START_STICKY to improve resource/battery optimization.

You can't set autostart to be enabled by-default programmatically.

Many solutions/suggestions have already been answered in many threads.
This one is taken from this thread, it takes user to respective auto-start/startup-manager/security-center, you can ask user to enable auto-start for your app by showing toast/alert, rest all depends on user:

try {
    Intent intent = new Intent();
    String manufacturer = android.os.Build.MANUFACTURER;
    if ("xiaomi".equalsIgnoreCase(manufacturer)) {
        intent.setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity"));
    } else if ("oppo".equalsIgnoreCase(manufacturer)) {
        intent.setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.permission.startup.StartupAppListActivity"));
    } else if ("vivo".equalsIgnoreCase(manufacturer)) {
        intent.setComponent(new ComponentName("com.vivo.permissionmanager", "com.vivo.permissionmanager.activity.BgStartUpManagerActivity"));
    } else if("oneplus".equalsIgnoreCase(manufacturer)) { 
        intent.setComponent(new ComponentName("com.oneplus.security", "com.oneplus.security.chainlaunch.view.ChainLaunchAppListAct‌​ivity")); }

    List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    if  (list.size() > 0) {
        context.startActivity(intent);
    } 
} catch (Exception e) {
    Crashlytics.logException(e);
}

P.S. auto-start is enabled by-default for some apps like Facebook, Instagram and other Facebook family apps, they may have an agreement with device manufacturers.

global_warming
  • 833
  • 1
  • 7
  • 11
  • i have already visited that thread and the answer above yours (from @Nirav Joshi) is almost the same but problem is that after enabling those options i still can't get the expected results – Adeel Turk Jan 09 '18 at 06:25
  • So, `Service` isn't running after enabling auto-start? – global_warming Jan 09 '18 at 06:28
  • Sometimes it revokes after a time-period of 5-10 mins, depends on resources available and resources required by your service, please check in running services after 5-10 minutes. – global_warming Jan 09 '18 at 06:35
  • ahan.. ok i will get back to this thread soon .. right now i m in a rush.. – Adeel Turk Jan 09 '18 at 06:43