I am working on a simple project which is responsible to launch and quit another installed application (let's call it "abc") on the tablet. The other application ("abc") is already installed in tablet. I can launch it using Intent. But need to find a way to quit it as well.
Here is the template of my mainActivity.java file.
 public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final LinearLayout parent = findViewById(R.id.parent);
        Button launchApp = (Button) findViewById(R.id.button);
        Button quitApp = (Button) findViewById(R.id.button2);
    
        launchApp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.abc");
                if (launchIntent != null) {
                    startActivity(launchIntent);
                } else {
                    Toast.makeText(MainActivity.this, "There is no package available in android", Toast.LENGTH_LONG).show();
                }
            }
        });
        quitApp.setOnClickListener(new View.OnClickListener() {
            @Override
           public void onClick(View v) {
              //Add code to close the installed app on tablet ("com.abc")
           }
        });
   }
}
This is also my activitymanifest.xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.launcherQuitterApp">
    <!--uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" /!-->
    <!--uses-permission android:name="android.permission.com.abc"
        tools:ignore="ProtectedPermissions" /!-->
    <uses-permission android:name="android.permission..com.abc"></uses-permission>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.LauncherQuitterApp">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <queries>
        <package android:name="com.abc"/>
    </queries>
</manifest>
I have tried the suggestions in the following threads, but none of them worked for me:
- Followed the suggestion of this thread, but when I tried to list all running applications, it only reported the running application (the one through which i want to close the other application)