Questions Tags Users Companies COLLECTIVES Explore Collectives TEAMS Stack Overflow for Teams – Start collaborating and sharing organizational knowledge. How to close an app open with start_activity() with Python in Appium?

I am using Python 3.10 and Appium to automate a real Android device.
I open the main app I want to automate with some desired capabilities.
Then I use:


to start other apps I need.

My device has a small RAM capacity and when too many apps are open, it starts to slow down and disturbs the execution of my script. But I don’t want to stop the first app I open with the desired capabilities. I would like to stop all the other apps. I want to kill the unnecessary app open on my device.
I read about this command:


It will close the app open with desired capabilities. This is not what I want.

So my question is “How to stop an app open with start_activity() and not the one with desired capabilities?”