neverEndingProcessAndroid7- icon indicating copy to clipboard operation
neverEndingProcessAndroid7- copied to clipboard

Killed when swiped from recent or removed from task manager.

Open poralcode opened this issue 3 years ago • 1 comments

When the application is swiped, it also killed the service.

poralcode avatar Jun 10 '21 03:06 poralcode

On MIUI, the AUTOSTART permission should be Enabled to the application. This will automatically restart the service if it's been remove or swipe from the TaskManager.

The problem here is you won't be able to programmatically do that (unless your phone is rooted) as it's a part of the security and battery saver features of MIUI. However, you can show the AUTOSTART option and let the user Enabled it for the application.

private void ShowAutoStartOption() {

        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 ("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"));
            }

            List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
            if  (list.size() > 0) {
                startActivity(intent);
            }
        } catch (Exception e) {
            Log.e("exc" , String.valueOf(e));
        }
    }

Known applications such as Facebook, Facebook Messenger, Twitter, Instagram, WhatsApp are whitelisted by the manufacturer and will have the option enabled automatically when you installed those apps.

poralcode avatar Jun 10 '21 06:06 poralcode