Appium :check app is background of foreground?

how do i check the app is in foreground or background ? is there any python appium API for this ?

@Laxmi_Rukka when you app in foreground you can see some element specific to your app. if you can not see them => your app is in background OR crashed OR closed OR …

@Aleksei, but i would like to know from the API level, or do you know any API which will make the foreground always ?

@Laxmi_Rukka with Android you can check

((AppiumDriver) driver).currentActivity()

and see if it yours :slight_smile:

@Aleksei you means that will foreground the app ?

@Laxmi_Rukka yes. this should return current activity in foreground. for iOS only left check screen for elements of your app.

sorry to ask tomany Q, what happens if i call this method on the activity which is already active?

i mean in the device the activity is in the foreground and i assumed and tried to launch the activity. will it would be ignored that the activity is already opened ?

@Laxmi_Rukka i do not understand - why you can not test yourself?

i tested with mine app:


got output:

    sleep - 3
    sleep - 100

“.Launcher” is LG phone launcher activity

@Aleksei do you have python code on this?

anyways i will try similar with python
thanks a lot

Hi , How to find forground activity on ios ?