我正试图杀死或重启该应用,以便在json解析时可以刷新网址列表,
该应用没有启动器,无法直接启动:
https://play.google.com/store/apps/details?id=ru.iptvremote.android.iptv.core&hl=en
我正在使用此代码,但是没有用,我也在android manifest.xml中做了permissin
<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");
}
}
答案 0 :(得分:0)
您可以这样杀死您的应用程序;
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);
答案 1 :(得分:-1)
这对我来说很好
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();