(AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE) vs Accountmanager.get(context)

473 views Asked by At

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

1

There are 1 answers

0
Emil On

If you look into Accountmanager.get(context) you'll see that it's basically a shortcut to first option with null check:

public static AccountManager get(Context context) {
    if (context == null) throw new IllegalArgumentException("context is null");
    return (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
}