I'm using appuim for interaction between my Android device and java code. And I faced with problem that on some kind of devices(including emulators) after pressing on Home button, appium return incorrect current activity (it returns previuos activity which is currently must be minimized). I found that appium used dumpsys window windows
with grabbing mFocusedApp
value for getting current app. I read another answers about getting Android current activities, and mostly it recommend to use:
adb shell "dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'"
That was the source of the problem, because after pressing Home button mCurrentFocus
and mFocusedApp
linked to different activities. But I can't find any explanation the difference between these fields. And why appuim uses only mFocusedApp
for it?
The explanation of the difference between
mCurrentFocus
andmFocusedApp
stares right at you:The
mCurrentFocus
is aWindow
(just aview
which may or may not have anActivityRecord
associated with it)The
mFocusedApp
is anAppWindowToken
(anapp
Token
which will always have anActivityRecord
)So when input focus switches to a
view
with anactivity
- bothmCurrentFocus
andmFocusedApp
would show the sameactivity
. But sometimes focus switches to aview
without anactivity
(like parts of SystemUI, etc) - thenmCurrentFocus
will be showing thatview
butmFocusedApp
will still be showing theActivityRecord
of theapp
which had the focus before the last switch.