but when this part of the code runs nothing happens and it doesn't simulate the back button being pressed. Before people recommend finish() or onBackPressed(), they will not work for my required implementation because I need both the home button and the recents button to be triggered too and that apparently can be done by triggering keyevents.

XDA Developers was founded by developers, for developers. It is now a valuable resource for people who want to make the most of their mobile devices, from customizing the look and feel to adding new functionality.Are you a developer?