I have an activity that overrides onBackPressed()
, and within this function, I explicitly call finish()
, since I need to do some clean up before the app exits.
When I do run the app normally, and click on the BACK
key, the app exits normally.
When I run the monkey tool with the following command,
adb shell monkey -v --pct-syskeys 100 -p com.my.app 100
according to the logs, the onBackPressed()
function is called, but the finish()
does not close the activity/app. I've been trying to figure out what the problem is for sometime, but could not so far. Any help is appreciated.
EDIT:
As per the comment, I'm posting the onBackPressed()
code:
@Override
public void onBackPressed() {
if (bIsBackKeyPressed)
return;
// do some clean up
bIsBackKeyPressed = true;
finish();
}
The reason I'm using the bIsBackKeyPressed
flag, is because the monkey tool sends the BACK
key multiple times.
It is possible that this happens in conjunction with other key presses, along with the BACK
key, but I'm not sure about that.
Thanks,
Rajath