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:

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);
    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.


Post a Comment

Popular posts from this blog

Snippet: align a TextView around an image

NotificationListenerService and kitkat