如何清除分贝时,应用程序在Android是卸载 [英] How to clear db when app is uninstalled in android

查看:188
本文介绍了如何清除分贝时,应用程序在Android是卸载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即时通讯使用数据库来存储信息,如果我卸载我的应用程序,并重新安装相同的应用程序,数据库仍然是相同的,但我想清楚了我的数据库,如何解决此问题?

Im using database to store messages, and if i uninstall my app and again reinstall the same app, the db remains same, but i want to clear my database, how to solve this?

推荐答案

要听卸载事件中,你必须实现广播接收,如:

To listen the uninstall event you have to implement a broadcast received, like:

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
    android:name=".UninstallIntentActivity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <action android:name="android.intent.action.DELETE" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:scheme="package"  />
    </intent-filter>



</activity>

</application>

然后在你的UninstallIntentActivity你必须使用下一行删除你的数据库:

And then in your UninstallIntentActivity you have to use the next line to delete your database:

context.deleteDatabase(DATABASE_NAME);

您可以看到更多的关于这个话题在这里<一个href=\"http://stackoverflow.com/questions/8633761/listen-broadcast-before-application-uninstall\">Listen广播应用程序之前卸载

You can see more about this topic here Listen Broadcast Before application uninstall

我希望这对你的作品。

这篇关于如何清除分贝时,应用程序在Android是卸载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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