优化杀进程的方式

lowmem
Matthew 1 month ago
parent 96b07fa223
commit 06f38f3ff0

@ -171,7 +171,7 @@ public class MpMasterService extends Service {
@Override @Override
public IBinder onBind(Intent intent) { public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service. // TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented"); // throw new UnsupportedOperationException("Not yet implemented");
} }
@Override @Override
@ -1300,11 +1300,11 @@ public class MpMasterService extends Service {
//重启MpApp应用 //重启MpApp应用
public static void restartMpApp(Context context, String reason) { public static void restartMpApp(Context context, String reason) {
SysApi.forceStopApp(context, MicroPhotoContext.PACKAGE_NAME_MPAPP); forceStopMpApp(context);
try { try {
Thread.sleep(100); Thread.sleep(100);
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw new RuntimeException(e); e.printStackTrace();
} }
//// 然后启动目标应用 //// 然后启动目标应用
try { try {
@ -1322,13 +1322,24 @@ public class MpMasterService extends Service {
} }
} }
private static void forceStopMpApp(Context context) {
if (Build.TIME < 1744905600000L) {
SysApi.forceStopApp(context, MicroPhotoContext.PACKAGE_NAME_MPAPP);
} else {
int pid = MicroPhotoContext.getProcessIdOfService(context, MicroPhotoContext.PACKAGE_NAME_MPAPP, MicroPhotoContext.SERVICE_NAME_MPSERVICE);
if (pid != 0) {
android.os.Process.killProcess(pid);
}
}
}
//根据包名重启应用 //根据包名重启应用
public static void restartAppByPackage(Context context, String packagename, String reason) { public static void restartAppByPackage(Context context, String packagename, String reason) {
SysApi.forceStopApp(context, packagename); forceStopMpApp(context);
try { try {
Thread.sleep(100); Thread.sleep(100);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace();
} }
//// 然后启动目标应用 //// 然后启动目标应用
try { try {

Loading…
Cancel
Save