-2

I want In Main app button click, B App exit.

in other words, I want another app exit on android.

I know my app exit command.

moveTaskToBack(true);
finish();
android.os.Process.killProcess(android.os.Process.myPid())

but this source. recently execute app exit source.

perhaps, use package name ? please advice for me.

thanks.

@update

add manifest

uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  ActivityManager am = (ActivityManager) getSystemService(Activity.ACTIVITY_SERVICE);
  am.killBackgroundProcesses("app exit package name");
  }
}
chohyunwook
  • 411
  • 1
  • 5
  • 18
  • look here http://stackoverflow.com/questions/38842962/i-really-really-want-a-close-button-to-terminate-the-android-application/38843217#38843217 – Sohail Zahid Aug 18 '16 at 09:18
  • simply create a broadcast and receive it in the Activity you wanna close – Zar E Ahmer Aug 18 '16 at 11:26
  • Or start A Activity by startActivityForResult and onButton click receieved it and finish that Activity. But for this you must have to start your Activity from that particular activity – Zar E Ahmer Aug 18 '16 at 11:28

1 Answers1

0

You can use the killBackgroundProcesses() method of ActivityManager:

ActivityManager am = (ActivityManager) getSystemService(Activity.ACTIVITY_SERVICE);
am.killBackgroundProcesses(packageName);

Please, note that your app needs to own the KILL_BACKGROUND_PROCESSES permission. Thus, in the AndroidManifest.xml, you need to include:

<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
Quick learner
  • 10,632
  • 4
  • 45
  • 55