How to close another app in Android?

后端 未结 4 1555
悲哀的现实
悲哀的现实 2020-11-29 06:34

I have been developing an app, and I need to close another app in my code. Does anyone know any api to call to close an app?

BTW: my app will be pre-installed.

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-29 06:59

    Try This

        ActivityManager am = (ActivityManager) getApplicationContext().getSystemService("activity");
        Method forceStopPackage;                
        forceStopPackage =am.getClass().getDeclaredMethod("forceStopPackage",String.class);
        forceStopPackage.setAccessible(true);
        forceStopPackage.invoke(am, pkg);
    

    In manifest file add this

    
    

提交回复
热议问题