0

My app starts others apps (upon user request) using this simple code:

Intent LaunchApp = getPackageManager().getLaunchIntentForPackage("the.external.app.package");                 
startActivity( LaunchApp );

Is there a way to finish or close that app?

I have tried with ActivityManager.killBackgroundProcesses() and with android.os.Process.sendSignal(pid, android.os.Process.SIGNAL_KILL) but no success.

The idea is to do something like this: If the app connects to the car bluetooth then it starts the music player automatically. Once the bluetooth is disconnected it should close the music player.

Thanks

Ton
  • 9,235
  • 15
  • 59
  • 103

1 Answers1

0

You can close activity without killing process.

  1. Use startActivityForResult() instead startActivity()

    startActivityForResult( LaunchApp, 100 );// reques code = 100
    
  2. Close activity by request code when you need that

    finishActivity( 100 );
    
Roman Black
  • 3,501
  • 1
  • 22
  • 31