Posts

Showing posts with the label Toast

Toast and duration : LENGTH_LONG and LENGTH_SHORT are FLAGS!

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