自定义帐户身份验证。账户清理后,从设备中删除自定义、账户、身份验证、帐户

2023-09-06 07:59:15 作者:浪痞孤王

有没有一种方法来获得某种通知/广播/等。当一个自定义帐户从同步设置帐户与去掉?

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.

推荐答案

您有两种选择:

您可以使用 addOnAccountsUpdatedListener方法的AccountManager 添加侦听在活动的的onCreate 方法服务 - 确保您删除的监听器在你的的onDestroy 法(即不要在使用本一个循环运行的服务)或者上下文用于检索的AccountManager 将永远不会被垃圾回收

You can use the addOnAccountsUpdatedListener method of AccountManager to add a listener in the onCreate method of an Activity or Service -- make sure you remove the listener in your onDestroy method (i.e. do NOT use this in an endlessly running service) or the Context used to retrieve the AccountManager will never be garbage collected

AccountsService 将播出用行动 AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION每一个帐户添加,删除或更改时间,你可以添加一个接收器。

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.