#102. "ADB Concepts-14" - How to 'Launch an App & Close an App' by using ADB Command

#102. "ADB Concepts-14" - How to 'Launch an App & Close an App' by using ADB Command

In this Article, we are going discuss about launch/Stopping an app from the command line using ADB (Android Debug Bridge).

Topic-1 : Launching an App:

Though it’s easiest to launch an app by simply selecting it from the Home Menu, but we can also launch an app over adb

Basic Syntax:

adb shell am start -S <package-name>/<activity-name>        

Here’s a breakdown of the command:

  • adb shell: Opens a shell on the connected Android device.
  • am start: Uses the Activity Manager (AM) to start an activity.
  • -S: Forces the app to stop before starting, essentially restarting the app (useful for testing fresh app launches).
  • <package-name>: The application’s package name (e.g., com.example.myapp).
  • <activity-name>: The full name of the activity to start. If it's the main activity, it’s often something like com.example.myapp.MainActivity.

Example:

Article content
Topic -2 : Stopping/Closing an App:

Though it’s easiest to close an app by simply hitting the [X] button on the Home Menu, but we can also close an app over adb:

Basic Syntax:

adb shell am force-stop <package-name>        

  • adb shell: Opens a shell on the connected Android device.
  • am: Activity Manager — a tool within Android that handles activities (apps), services, etc.
  • force-stop: A subcommand to forcefully stop a running app. It stops the app’s process and services..
  • <package-name>: The application’s package name (e.g., com.example.myapp).

Example:

Article content

What Happens When You Run This:

  • Android’s ActivityManager tells the system to immediately stop the app.
  • The app’s process is killed.
  • The app will not run again until you or the system explicitly starts it.


Get a step-by-step walkthrough in the video below!


🚀 Enhance Your Automation Skills with My Content!

📺 YouTube – AppiumGuide Explore in-depth tutorials and hands-on guides on mobile automation testing. 🔗 Watch Now

✍️ Medium – Articles & Insights Stay updated with expert-written articles on Appium, Selenium, and test automation strategies. 🔗 Read Here

💻 GitHub – Open-Source Contributions Access automation frameworks, sample projects, and best practices in mobile testing. 🔗 Explore Code

👍 𝗟𝗶𝗸𝗲 if you found it helpful!🔁 𝗥𝗲𝗽𝗼𝘀𝘁 with your network!🔖 𝗦𝗮𝘃𝗲 for future use!📤 𝗦𝗲𝗻𝗱 to your connections!💬 𝗖𝗼𝗺𝗺𝗲𝗻𝘁 your thoughts below!



To view or add a comment, sign in

More articles by Ramesh Kodumuru

Insights from the community

Others also viewed

Explore topics