自定义帐户身份验证。账户清理后,从设备中删除 [英] Custom Account authenticator. Cleanup after account is removed from device
问题描述
有没有一种方法来获得某种通知/广播/等。当一个自定义帐户从同步设置帐户与去掉?
Is there a way to get some kind of notification/broadcast/etc. when a custom account is removed from "Accounts & sync settings"?
予有可促进多个用户设备上的应用程序(此为企业使用),并使用单一SQLite数据库。说我创建多个用户对于我的设备上的应用程序和填充数据库与相关的数据只向那些两个用户。我在这里的问题是,如果用户的一个是从帐户与同步设置去掉我也没有办法清理数据库和/或SD卡上的某些外部文件。
The application I have can facilitate multiple users on a device (this is for a corporate use) and uses a single SQLite database. Say I create multiple users for my application on a device and populate database with data that is relevant only to those two users. My problem here is that if one of the user is removed from "Accounts & sync settings" I have no way to cleanup database and/or some external files on SD card.
我可以在冗余表重复的用户信息,并将它与已注册帐户比较,然后从数据库中取出用户数据,如果在从的AccountManager表和科目[]数组用户信息不匹配。感觉脏了我。
I could duplicate user information in a redundant table and compare it with registered accounts and then removing user data from the database if user information in the table and Account[] array from AccountManager does not match. Feels dirty to me.
推荐答案
您有两种选择:
-
您可以使用
<一个href="http://developer.android.com/reference/android/accounts/AccountManager.html#addOnAccountsUpdatedListener%28android.accounts.OnAccountsUpdateListener,%20android.os.Handler,%20boolean%29">addOnAccountsUpdatedListener$c$c>方法
的AccountManager
添加侦听在活动的
或的onCreate
方法服务
- 确保您删除的监听器在你的的onDestroy
法(即不要在使用本一个循环运行的服务)或者上下文
用于检索的AccountManager
将永远不会被垃圾回收
You can use the
addOnAccountsUpdatedListener
method ofAccountManager
to add a listener in theonCreate
method of anActivity
orService
-- make sure you remove the listener in youronDestroy
method (i.e. do NOT use this in an endlessly running service) or theContext
used to retrieve theAccountManager
will never be garbage collected
在 AccountsService
将播出用行动 <一个意图href="http://developer.android.com/reference/android/accounts/AccountManager.html#LOGIN_ACCOUNTS_CHANGED_ACTION">AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION$c$c>每一个帐户添加,删除或更改时间,你可以添加一个接收器。
The AccountsService
will broadcast an intent with the action AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION
every time an account is added, removed or changed which you can add a receiver for.
这篇关于自定义帐户身份验证。账户清理后,从设备中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!