5

I have been searching for answers regarding this problem with China phone (Oppo, Huawei, XiaoMi, Vivo, etc.) when app is swiped up (close), the background services stopped running.

Most of the solutions were:

  1. Include START_STICKY and use AlarmManager to start service.
  2. Programmatically direct user to auto-start manager to enable app by user.
  3. Manually exclude my app from power saving mode or include my app as protected apps.

My question is how does apps like Whatsapp still receives message or notification even swiped up? Furthermore, the solutions mentioned in 1. and 2. doesn't work if phone restarts, but how Whatsapp still can receive messages? I have tested Samsung devices, they have no problem running background services even though the app is swiped up. Has anyone face the same problem with China phone?

  • Comments are not for extended discussion; this conversation has been [moved to chat](http://chat.stackoverflow.com/rooms/162606/discussion-on-question-by-gh-liew-application-background-service-stopped-when-sw). – Andy Jan 05 '18 at 14:21
  • did you found any solution to our problem? – Ashutosh Sagar Feb 13 '18 at 11:20
  • @AshutoshSagar Sadly, no. –  Feb 14 '18 at 03:53

2 Answers2

5
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"));
            } else if ("Letv".equalsIgnoreCase(manufacturer)) {
                intent.setComponent(new ComponentName("com.letv.android.letvsafe", "com.letv.android.letvsafe.AutobootManageActivity"));
            } else if ("Honor".equalsIgnoreCase(manufacturer)) {
                intent.setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity"));
            }
            else if ("huawei".equalsIgnoreCase(manufacturer)) {
                intent.setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity"));
            }
            else if ("asus".equalsIgnoreCase(manufacturer)) {
                intent.setComponent(new ComponentName("com.asus.mobilemanager","com.asus.mobilemanager.autostart.AutoStartActivity"));
            }
            else {
                Log.e("other phone ", "===>");
            }
            List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
            if (list.size() > 0) {
                startActivity(intent);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
Coldfin Lab
  • 361
  • 3
  • 8
  • 2
    Huwai device no more support with **com.huawei.systemmanager.optimize.process.ProtectActivity** change it to **com.huawei.systemmanager.appcontrol.activity.StartupAppControlActivity** – Nirmal Shethwala Oct 03 '18 at 14:59
  • @NirmalShethwala, this will cause SecurityException. You must use `"com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity"`, because not any others ways exist. – AlexS Jul 04 '19 at 12:38
  • where i can set this? – newbie Sep 24 '19 at 14:15
0

I am still looking for the answer. I have contacted Google support team and they replied as follow:

Upon discussion with our engineers, this is really the expected behavior. For the reason that they use a stock ROM that disables the re-starting of background services for most apps. Users should manually enable the auto-starting of background services as they are disabled by default. This can not be programmatically enabled for all devices. So you'll have to prompt your users to perform the steps manually. Please check out this guide to learn more about this workaround.

Faisal Shaikh
  • 3,900
  • 5
  • 40
  • 77