How to Restart an Android Device from the Command Line

How to Restart an Android Device from the Command Line

21 May 2024 Stephan Petzl Leave a comment Tech-Help

Working with Android devices in a Linux environment can sometimes lead to the Android GUI hanging or becoming unresponsive. If you’re managing such devices, particularly in a development or testing context, you might encounter a need to restart the Android interface without affecting the underlying Linux system. This is especially important when running scripts that interact with the Android layer.

Restarting Android using ADB

One of the simplest and most effective methods to restart an Android device from the command line is using the Android Debug Bridge (ADB). ADB is a versatile tool that allows you to communicate with an emulator instance or connected Android-powered device.

  1. Connect your device to the computer or ensure it’s connected over the network.
  2. Open a terminal window.
  3. Type the following command: adb reboot

This command will initiate a reboot of the Android OS on the device. It’s important to note that this will not reboot the Linux system itself, but only the Android environment running on top of it.

Running Shell Scripts via ADB

If you need to run a complete shell script that includes a reboot of the Android system, you can do so with ADB:

adb shell <command>

Replace <command> with the necessary shell script or command you wish to execute on the Android system.

Targeting a Specific Device

If you’re working with multiple devices or emulators, you can target a specific device for reboot by using its device ID:

  1. Retrieve the device ID by running: adb devices
  2. Use the device ID to target the device: adb -s <device_id> reboot

You can find additional information on ADB commands in the official documentation here.

Rebooting with Broadcast Intents

Another method to reboot the device is by sending a broadcast intent for the BOOT_COMPLETED action. This can be done with the following command:

adb shell am broadcast -a android.intent.action.BOOT_COMPLETED

This command simulates the system boot completed action and can be useful in specific scenarios where a full reboot command is not suitable.

Integrating Repeato for Test Automation

Managing Android devices and ensuring that they operate smoothly can be a significant part of testing and development workflows. Repeato, a no-code test automation tool for iOS and Android, can help streamline these processes. With its built-in ADB support and the ability to send ADB commands via script steps, Repeato allows you to seamlessly integrate device management commands into your automated testing sequences.

For instance, if a test case requires a device to reboot before proceeding, you can include the adb reboot command within Repeato’s script steps to ensure that the test environment is consistently controlled. This method is both efficient and effective, thanks to Repeato’s AI and computer vision capabilities, which make test creation and maintenance fast and reliable.

To learn more about how Repeato can improve your testing workflow, visit our documentation or download the tool from our download page.

If you have further questions or need support, feel free to reach out through our contact form.

Like this article? there’s more where that came from!