如何在 android 中终止此应用程序或重新启动
How to kill this app in android or restart
我正在尝试终止或重启此应用,以便在 json 解析时刷新 url 列表,,
此应用没有启动器,无法直接启动:
https://play.google.com/store/apps/details?id=ru.iptvremote.android.iptv.core&hl=en
我正在使用此代码但没有用,我也在 android manifest.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();
我正在尝试终止或重启此应用,以便在 json 解析时刷新 url 列表,,
此应用没有启动器,无法直接启动:
https://play.google.com/store/apps/details?id=ru.iptvremote.android.iptv.core&hl=en
我正在使用此代码但没有用,我也在 android manifest.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();