How to programmatically clear application data


Question

I am developing automated tests for an android application (using Robotium). In order to ensure the consistency and reliability of tests, I would like to start each test with clean state (of the application under test). In order to do so, I need to clear the app data. This can be done manually in Settings/Applications/Manage Applications/[My App]/Clear data

What is the recommended way to get this done programmatically?

1
148
12/14/2015 9:06:50 PM

You can use the package-manager tool to clear data for installed apps (similar to pressing the 'clear data' button in the app settings on your device). So using adb you could do:

adb shell pm clear my.wonderful.app.package
170
12/21/2011 11:11:49 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon