N Kaushik

How to clear Android application data and restart an App with adb

December 22, 2022

How to clear Android application data and restart an App with adb:

Suppose you want to clear all data of your application and you don’t want to clear the data from settings. adb provides a way to do that. In this short post, I will show you how to use adb to clear the data of an Android app and restart it with adb.

Cleaning data using adb:

To clear data with adb, we have to make sure that the device is connected to the system. Open one terminal and run the below command to check that:

adb devices

It will list down all connected devices as like below:

List of devices attached
<name>	device

The name will be you device name. If it doesn’t show your device, you can recheck your connection.

Once the device is recognized by adb, make sure that the app is installed on that device. Run the below command to clean all data of the app:

adb shell pm clear <app-package-name>

You need to replace the with your app’s actual package name. For example, if the package name is com.demo.myapp, the command will be adb shell pm clear com.demo.myapp.

How to restart the app with adb:

adb doesn’t provide any single command to restart an app. But it has commands to force stop and start an application. We can force stop the app first and start it with the below commands:

Kill the app:

adb shell am force-stop com.package.name

Start the app:

adb shell am start -n com.package.name/com.package.name.MainActivity

You need the package name and the activity name that is registered as the Main activity in the app.

Benefits of this approach:

This approach has many benefits while developing Android applications. You don’t have to reinstall the app to clear its data. You can start the app like a freshly installed app. Also, if you get any invalid data error, this will be a faster approach rather than reinstalling the app.


Subscribe to my Newsletter