How to identify application is closed


I have query here. Please help as soon as possible.

How to identify my mobile application is closed or crashed. Please any one suggest me a logic to find my app is closed when running the test.

Please it’s urgent suggest me

This is bit trick
You have to take help of adb in this case. Execute below command using java code and read it’s ouput
if it contains u r app process running it means app is not killed else it is crashed and killed.

C:>adb shell

shell@condor_umtsds:/ $ ps
radio 1638 302 415524 32276 ffffffff 00000000 S

// Below command should work not working for me try at u r end once. If this work u will directly get a string from cmd to check status of app
shell@condor_umtsds:/ $ ps | awk ‘{print $8}’
ps | awk ‘{print $8}’
/system/bin/sh: awk: not found
127|shell@condor_umtsds:/ $

Thanks amit for your reply.

We are implemented same logic. Where my logic searche for PID and “Fatal” word. But it’s not stable logic.

I’m looking for different logic like, If running app is closed. so i can consider as a crash. Is this possible to implement in java.

Please suggest me.

No exact idea,

You can listen to adb logs specific to u r app, if they contains any exceptions or below command is generating any logs
adb logcat | grep “appPackage”

or store them in a file and time to time if file size is increasing, if it’s increasing then script is running fine else not…
adb logcat > file.log

You can also try to listen appium server logs, if u r starting appium server using java code.

Appium also generate static logs something like
Shut down UIAutomator as no new commands came in last 60 sec

1 Like

You can use ‘adb shell am monitor’ in a separate thread and check for “ERROR: PROCESS CRASHED”. If you see that line, the next several lines will show the identity of the process and the backtrace


Willosser thx for reply, I’m using same logic as of now.

but looking for different method. is possible to identify the application closed during test ?


  1. Application running as per test suite.[Assume test 3]
  2. During test 4 app closed. [Point here is how to identify the app is closed? other than adb log]
  3. If app is closed i’ll consider as a crash and reopen the app.

Suggest me the way for above logic.

if expect that while running app is in foreground try to check:

        System.out.println("is app running foreground: "+driver.getPageSource().contains("your_package_name"));
        sleep(10); //close, crash or send app into background now
        System.out.println("is app running foreground : "+driver.getPageSource().contains("your_package_name"));

Thanks @Aleksei, I’ll try this logic n let you know.

I would use the ‘ps’ logic above if I just needed to know if the different apps are running.

Hey @Karthik_Gowda if you are using node, we created a module that let you know if an app is running. It actually wraps adb responses. Using grep it may throw some error on some devices.
Check it out,