1, the introduction









Android P is coming: The real nightmare of app survival and notification
A comprehensive inventory of the true operation effect of the current Android background Preservation solution (by 2019)















2. About the author



Net NanBox:






GitHub


3. Related articles



If you want to learn more about the current challenges of backend preservation on Android, read:





  • Android P official coming soon: The real nightmare of app survival and push notifications.



If you want to look back at some of the best Android technologies ever, here’s a good read:





  • A Comprehensive Review of the real Operation Effect of the Current Android Background Preservation Scheme (by 2019)
  • “Application survival (1) : dual-process daemon survival practices under Android6.0”
  • Android6.0 and above (process prevention)
  • Android6.0 and above survival practices (killed and resurrected)
  • How to Keep the Android Process Alive: One Article to Solve All Your Questions
  • Summary of Message Push on Android: Implementation principle, Heartbeat Survival, Problems encountered, etc.
  • An in-depth look at the Little Matter of Android News Push
  • Why Does TCP – based MOBILE IM Still Need heartbeat Keepalive mechanism?
  • “Wechat Team original Sharing: Android version of wechat background Survival combat Sharing (Process survival)”
  • “Sharing of Rongyun Technology: Practice of Network Link Preservation Technology of Rongyun Android IM Products”


4. Android keeps the status quo



Android P is coming: The real nightmare of app survival and notification




















5, elegant survival?



A two-process daemon for Android6.0
Android6.0 and above (process prevention)
Android6.0 and above survivability practices (killed and resurrected)














6, join the white list of background operation, can be elegant to achieve survival









You’ll usually see the following two:






















First, configure the permissions in the Androidmanifest.xml file:


<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />Copy the code



You can use the following methods to determine whether our application is in the whitelist:


@RequiresApi(api = Build.VERSION_CODES.M) private boolean isIgnoringBatteryOptimizations() { boolean isIgnoring = false;  PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); if (powerManager ! = null) { isIgnoring = powerManager.isIgnoringBatteryOptimizations(getPackageName()); } return isIgnoring; }Copy the code



If you are not in the whitelist, you can apply to be added to the whitelist by using the following code:


@RequiresApi(api = Build.VERSION_CODES.M) public void requestIgnoreBatteryOptimizations() { try { Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS); intent.setData(Uri.parse("package:" + getPackageName())); startActivity(intent); } catch (Exception e) { e.printStackTrace(); }}Copy the code



When you apply, the app will display a window like this:












7. Add the multi-vendor adaptation method to the background whitelist


7.1 Basic Information





















First we can define two methods:


Private void showActivity(@nonNULL String packageName) {Intent Intent = getPackageManager().getLaunchIntentForPackage(packageName); startActivity(intent); Private void showActivity(@nonNULL String packageName, @NonNull String activityDir) { Intent intent = new Intent(); intent.setComponent(new ComponentName(packageName, activityDir)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); }Copy the code








7.2 huawei



Manufacturer judgment:


public boolean isHuawei() { if (Build.BRAND == null) { return false; } else { return Build.BRAND.toLowerCase().equals("huawei") || Build.BRAND.toLowerCase().equals("honor"); }}Copy the code



Go to the startup management page of Huawei Mobile Phone Manager:


private void goHuaweiSetting() { try { showActivity("com.huawei.systemmanager", "com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity"); } catch (Exception e) { showActivity("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.bootstart.BootStartActivity"); }}Copy the code



Operation steps:
Application Startup Management -> Disable Application -> Enable Automatic startup





7.3 millet



Manufacturer judgment:


public static boolean isXiaomi() { return Build.BRAND ! = null && Build.BRAND.toLowerCase().equals("xiaomi"); }Copy the code



Jump to the page of self-start management of xiaomi Security Center:


private void goXiaomiSetting() {
    showActivity("com.miui.securitycenter",
        "com.miui.permcenter.autostart.AutoStartManagementActivity");
}Copy the code



Operation steps:





7.4 OPPO



Manufacturer judgment:


public static boolean isOPPO() { return Build.BRAND ! = null && Build.BRAND.toLowerCase().equals("oppo"); }Copy the code



Jump to OPPO mobile phone butler:


private void goOPPOSetting() { try { showActivity("com.coloros.phonemanager"); } catch (Exception e1) { try { showActivity("com.oppo.safe"); } catch (Exception e2) { try { showActivity("com.coloros.oppoguardelf"); } catch (Exception e3) { showActivity("com.coloros.safecenter"); }}}}Copy the code



Operation steps:





7.5 VIVO



Manufacturer judgment:


public static boolean isVIVO() { return Build.BRAND ! = null && Build.BRAND.toLowerCase().equals("vivo"); }Copy the code



Jump VIVO mobile phone butler:


private void goVIVOSetting() {
    showActivity("com.iqoo.secure");
}Copy the code



Operation steps:
Permission Management -> Automatic Startup -> Allow automatic startup of applications





7.6 the meizu



Manufacturer judgment:


public static boolean isMeizu() { return Build.BRAND ! = null && Build.BRAND.toLowerCase().equals("meizu"); }Copy the code



Jump to Meizu mobile phone butler:


private void goMeizuSetting() {
    showActivity("com.meizu.safe");
}Copy the code



Operation steps:
Permission Management -> Background Management -> Click Apply -> Allow Background running





7.7 samsung



Manufacturer judgment:


public static boolean isSamsung() { return Build.BRAND ! = null && Build.BRAND.toLowerCase().equals("samsung"); }Copy the code



Jump to Samsung Smart Manager:


private void goSamsungSetting() { try { showActivity("com.samsung.android.sm_cn"); } catch (Exception e) { showActivity("com.samsung.android.sm"); }}Copy the code



Operation steps:





7.8 Letv



Manufacturer judgment:


public static boolean isLeTV() { return Build.BRAND ! = null && Build.BRAND.toLowerCase().equals("letv"); }Copy the code



Jump leEco mobile phone butler:


private void goLetvSetting() {
    showActivity("com.letv.android.letvsafe", 
        "com.letv.android.letvsafe.AutobootManageActivity");
}Copy the code



Operation steps:





7.9 the hammer



Manufacturer judgment:


public static boolean isSmartisan() { return Build.BRAND ! = null && Build.BRAND.toLowerCase().equals("smartisan"); }Copy the code



Jump to mobile phone management:


private void goSmartisanSetting() {
    showActivity("com.smartisanos.security");
}Copy the code



Operation steps:


8, friends business salute?









Recently, it was found that a friend dong also followed up. Figure 1 is what we did, and Figure 2 is what Dong did:


















Appendix: More technical articles



A two-process daemon for Android6.0



Android6.0 and above (process prevention)



Android6.0 and above survivability practices (killed and resurrected)



How to keep the Android process alive: One article answers all your questions



Summary of Message push on Android: implementation principle, heartbeat survival, problems encountered, etc



Let’s take a closer look at the small matter of Android notifications



Why does TCP – based mobile IM still need the heartbeat keepalive mechanism?



Wechat team original sharing: Android version of wechat background to keep alive combat sharing (process to keep alive)



Wechat team original sharing: Android version of wechat background to live combat sharing (network to live)



Mobile IM practice: To realize the intelligent heartbeat mechanism of wechat on Android



Mobile IM practice: Analysis of heartbeat strategy of WhatsApp, Line and wechat



Android P is coming: The real nightmare of app survival and notification



A comprehensive inventory of the true operation effect of the current Android background Preservation solution (by 2019)



In this paper, I understand the mechanism of network heartbeat packet in instant messaging application: function, principle, implementation ideas, etc



Rongyun technology sharing: Network link preservation technology practice of Rongyun Android IM products



Correctly understand IM long connection heartbeat and reconnection mechanism, and start to implement (complete IM source code)



In 2020, will Android backend survive? Watch me do it gracefully!



More of the same…