Automate closing of applications in Android

前端 未结 1 759
后悔当初
后悔当初 2020-12-08 03:32

I\'ve read a lot of documentation and other posts about closing other apps. I know the documentation says Android isn\'t designed that way. Android wants to hibernate an app

相关标签:
1条回答
  • 2020-12-08 04:18

    What you said is perfectly possible. Just get the ActivityManager system service and then use .restartPackage() (deprecated) or .killBackgroundProcesses().

    ActivityManager activityManager = (ActivityManager) context.getSystemService("activity");
    activityManager.restartPackage(packageName);
    

    You will need:

    <uses-permission android:name="android.permission.RESTART_PACKAGES" />
    <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
    
    0 讨论(0)
提交回复
热议问题