如何以编程方式清除应用程序数据 [英] How to programmatically clear application data

查看:242
本文介绍了如何以编程方式清除应用程序数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为android应用程序开发自动化测试(使用Robotium).为了确保测试的一致性和可靠性,我想以干净状态(正在测试的应用程序的状态)开始每个测试.为此,我需要清除应用程序数据.可以在设置"/应用程序"/管理应用程序"/"[我的应用程序]/清除数据"中手动完成

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?

推荐答案

您可以使用包管理器工具清除已安装应用程序的数据(类似于按设备上应用程序设置中的清除数据"按钮). 因此,使用adb可以做到:

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

这篇关于如何以编程方式清除应用程序数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆