Toast and duration : LENGTH_LONG and LENGTH_SHORT are FLAGS!

How many times I've seen this code:
Surely I wrote it myself.
Toast.makeText (context, "My Text", 5000).show();
Pay attention!! Here you can see the doc:

This is the source:

LENGTH_LONG and LENGTH_SHORT ARE FLAGS!
Then duration is not expressed in milliseconds!
If you debug this code you can see:

And this is the central point,the NotificationManagerService:

This is the main row:
long delay = immediate ? 0 : (r.duration == Toast.LENGTH_LONG ? LONG_DELAY : SHORT_DELAY);
where:
    private static final int LONG_DELAY = 3500; // 3.5 seconds
    private static final int SHORT_DELAY = 2000; // 2 seconds
Then, the code written in the beginning IS WRONG
Toast.makeText (context, "My Text", 5000).show();< // IT IS WRONG!
Toast.makeText expects duration Toast.LENGTH_SHORT or Toast.LENGTH_LONG, a custom duration value is not supported.
However I have a little doubt: in the source we can find:
This time could be user-definable.
Honestly I can't find way to do this.Any suggestion is welcome.

Comments

  1. Great info you shared! Thank you! Thank you for sharing this useful information. I always appreciate you for letting us know. Your participation is much appreciated. In addition, I have an article Kohi Click Test. What is the Kohi Click Test?, you can learn more. Read this article to know how to use the new tool to click while playing.

    ReplyDelete

Post a Comment

Popular posts from this blog

AntiPattern: freezing a UI with Broadcast Receiver

NotificationListenerService and kitkat

How to centralize the support libraries dependencies in gradle