我正在尝试杀死或重新启动此应用程序,以便我可以在json解析时刷新网址列表,此应用程序没有启动器,无法直接启动: https://play.google.com/store/apps/details?id=ru.iptvremote.android.iptv.core&hl=en
我正在使用此代码但不起作用,我也在androidmanifest.xml中获得了许可
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>
@Override
protected void onStart() {
super.onStart();
jsonParse();
ActivityManager activityManager = (ActivityManager) this.getSystemService( ACTIVITY_SERVICE );
List<ActivityManager.RunningAppProcessInfo> procInfos = activityManager.getRunningAppProcesses();
for(int i = 0; i < procInfos.size(); i++){
if(procInfos.get(i).processName.equals("ru.iptvremote.android.iptv.core")){
Toast.makeText(getApplicationContext(), "app killed", Toast.LENGTH_LONG).show();
activityManager.killBackgroundProcesses("ru.iptvremote.android.iptv.core");
}
}
你可以像这样杀死你的应用;
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(0);
如果要重启;
Intent intent = new Intent(getApplicationContext(), SplashActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(0);
这对我很有用
ActivityManager am = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(startMain);
am.killBackgroundProcesses("put app package name here ");
Toast.makeText(getBaseContext(), "Process Killed : " + _put app package name here , Toast.LENGTH_LONG).show();