android - (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE) vs Accountmanager.get(context)
问题描述
What's the difference between -
AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
and
AccountManager accountManager =Accountmanager.get(context)
What should i use when-
1.Retrieving list of already created accounts in device
2.Adding my app's account to device
解决方案
如果您仔细研究,Accountmanager.get(context)
您会发现它基本上是使用空检查的第一个选项的快捷方式:
public static AccountManager get(Context context) {
if (context == null) throw new IllegalArgumentException("context is null");
return (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
}
推荐阅读
- javascript - Object.create 与 .prototype
- javascript - 关闭标签时,复选框元素应在复选框组中取消选中
- c - 如何将我的输出(二进制#)分成两组,用 C 中的单个空格分隔(无数组)
- java - 如果服务正在运行,如何在晚上 8 点停止服务?
- c# - 如何将 PDF Base64 转换为 pdf 然后 PDF 转换为 C# 中的图像
- jquery - 单击上一个按钮会抛出一个空白页面
- php - upgradeSchema 在 magento 2 中不起作用
- r - 删除不以特定字符串开头的行
- asynchronous - 为什么 Async.Sequential 不能按预期工作(但在 FSI 中工作)?
- python - 如何修复此抛物线回归以使回归图平滑?