[Question] Is there a setting that can restrict the scope of test automation?

I use Appium to build a test automation tool similar to Monkey. However, when I want to explore a specific app, the testing sometimes goes out of the scope of the app. For example, pressing a button may result in a navigation to another app, and pressing the back button may result in a navigation to the apps page.

I remember Monkey has a mechanism that can block events that results in such navigations. Is there a similar setting that I can use in Appium?

Hardly Appium or any monkey can predict button action hidden in app code.