[英]android sdk prompt toast message in account settings
I'm using an AbstractAccountAuthenticator and I want to single account for my app. 我正在使用AbstractAccountAuthenticator,我想为我的应用单独帐户。 So when the user is opting to add a new account for this app I want to prompt a message.
因此,当用户选择为此应用添加新帐户时,我想提示消息。 I saw other apps use a toast for the message, but for some reasons mine doesn't get displayed.
我看到其他应用程序使用Toast来显示消息,但由于某些原因,我没有显示。
I display the message like this: 我显示如下消息:
public Bundle addAccount() {
if (accounts.size() > 0) {
Toast.makeText(context, R.string.MSG_ONLY_ONE_ACCOUNT_IS_SUPPORTED, Toast.LENGTH_LONG).show();
return null;
}
}
Any ideas why? 有什么想法吗? I'm checking the accounts number in the addAccount() method from AbstractAccountAuthenticator.
我正在检查AbstractAccountAuthenticator的addAccount()方法中的帐号。
I've been looking around for the same. 我一直在寻找同样的东西。 The following answers have helped me: 1 , 2 .
以下的答案曾经帮助过我: 1 , 2 。
Using your code example: 使用您的代码示例:
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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.