帐户设置中的android sdk提示toast消息
我正在使用AbstractAccountAuthenticator,我想为我的应用创建一个帐户。因此,当用户选择为此应用程序添加新帐户时,我想提示一条消息。我看到其他应用程序使用祝酒词来显示消息,但由于某些原因,我的应用程序没有显示出来 我显示如下消息:帐户设置中的android sdk提示toast消息,android,authentication,message,account,Android,Authentication,Message,Account,我正在使用AbstractAccountAuthenticator,我想为我的应用创建一个帐户。因此,当用户选择为此应用程序添加新帐户时,我想提示一条消息。我看到其他应用程序使用祝酒词来显示消息,但由于某些原因,我的应用程序没有显示出来 我显示如下消息: public Bundle addAccount() { if (accounts.size() > 0) { Toast.makeText(context, R.string.MSG_ONLY_ONE_ACCOU
public Bundle addAccount() {
if (accounts.size() > 0) {
Toast.makeText(context, R.string.MSG_ONLY_ONE_ACCOUNT_IS_SUPPORTED, Toast.LENGTH_LONG).show();
return null;
}
}
你知道为什么吗?我正在从AbstractAccountAuthenticator检查addAccount()方法中的帐号 我一直在到处找同样的东西。以下答案对我有所帮助: 使用您的代码示例:
private final Handler handler = new Handler();
public Bundle addAccount(...) {
if (accounts.size() > 0) {
final Bundle bundle = new Bundle();
final String message =
mContext.getString(R.string.MSG_ONLY_ONE_ACCOUNT_IS_SUPPORTED);
bundle.putInt(AccountManager.KEY_ERROR_CODE, 1);
bundle.putString(AccountManager.KEY_ERROR_MESSAGE, message);
handler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
}
});
return bundle;
}
}
您是否验证了正在调用
addAccount()
,并且accounts.size()
实际上是>0
?是的,除了未显示的消息之外,一切都正常确保处理程序是在addAccount方法之外定义的,否则会出现错误(就像我所做的那样)。仅供大家参考。非常感谢您的帖子。救了我一天,谢谢你!,我不知道这是否是在Account Manager中显示错误的最佳方式,但它确实有效!