I'm using an AbstractAccountAuthenticator and I want to single account for my app. 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.
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.
You can use toast. cancel() befor showing next toast. cancelling won't reduce the toast time.
Create a new instance of Toast using makeText() method. Use getView() method to get the view of the Toast. Open MainActivity. java file and add function to show toast message.
Toast messages help to deliver simple feedback to the user. They most often follow an action performed by a user and provide information regarding the success or failure of that action. Toast messages are informative, have a lifespan of just a few seconds and take up a very small portion of the screen.
I've been looking around for the same. The following answers have helped me: 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;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With