I am trying to build an app that can click a particular button on another app. This is possible from Android 4.3+ using findAccessibilityNodeInfosByViewId which is part of Accessibility service. For example there is a very popular app called Greenify on Play Store that prevents other apps from running in the background by clicking "Force Stop" button of each running app.
Here is a code I found on Stackoverflow that explains how to do this.
Thanks Erel. I hope someone with good Java knowledge will be kind enough to create a B4A library for Accessibility. The feature has been available for nearly 5 years on Android system.