【问题标题】:How to kill this app in android or restart如何在android中杀死这个应用程序或重新启动
【发布时间】:2019-03-06 17:38:41
【问题描述】:

我正在尝试杀死或重新启动此应用程序,以便在 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 android-intent android-activity kill-process


    【解决方案1】:

    你可以像这样杀死你的应用程序;

    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);
    

    【讨论】:

    • ahmet koçu 我不想杀死我的应用程序我需要杀死另一个应用程序
    • 哦,好的。这应该工作activityManager.killBackgroundProcesses("ru.iptvremote.android.iptv.core");
    • ahmet koçu 不工作我在上面的代码中找到它之前就这样做了:(
    【解决方案2】:

    这对我很有效

     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();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-22
      相关资源
      最近更新 更多