1

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

4

1 回答 1

2

如果您仔细研究,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);
}
于 2018-12-26T12:53:30.073 回答