0

I have a simple launcher that enlists all the apps in a listview. I just want one feature in this launcher; when a certain item(say 5th item) in the listview is clicked, I want to completely kill all the previous opened apps and then open the 5th app enlisted there. I don't know what should I look for. I have the launcher app as the device admin and device owner and I think that it has something to do with DevicePolicyManager class. I also tried finishActivity(int requestcode) but it did not work. Below is the onItemClick() listener:

list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> av, View v, int pos,long id) {
                Intent i = manager.getLaunchIntentForPackage(apps.get(pos).name.toString());
                AppsListActivity.this.startActivity(i);

            }
        });
Ankit Shubham
  • 2,989
  • 2
  • 36
  • 61

1 Answers1

0

A little more context behind why you would like to kill the previously opened app before starting the activity of the next app would help. If I understand correctly, it would always be only one app to kill since only one app would always ever be running, right?

If you don't need to completely kill the apps, it would be much more elegant to suspend all packages setPackagesSuspended (if you're running API 24 or greater) except for the selected one and of course, your launcher. A suspended package will not be able to start activities. Its notifications will be hidden, it will not show up in recents, will not be able to show toasts or dialogs or ring the device. If you are worried about resources, is there a reason you can't trust Android to manage the resources and kill processes when it needs to?

Steve Miskovetz
  • 2,360
  • 13
  • 29