33

I am printing Toast message in my application to show notification but i want to know value of Toast.LENGTH_LONG and Toast.LENGTH_SHORT. What other values i can use.

Can anyone tell me what is the value of these two variables?

Shirish Herwade
  • 11,461
  • 20
  • 72
  • 111
CoDe
  • 11,056
  • 14
  • 90
  • 197
  • 2
    Possible duplicate of http://stackoverflow.com/questions/2220560/can-an-android-toast-be-longer-than-toast-length-long – rds Aug 09 '11 at 09:26

4 Answers4

47

There is another question that answers what you are looking for. The answers are:

private static final int LONG_DELAY = 3500; // 3.5 seconds
private static final int SHORT_DELAY = 2000; // 2 seconds

This was courtesy of FeelGood. You can find the whole thread below.

Can an Android Toast be longer than Toast.LENGTH_LONG?

Hope this helps.

Community
  • 1
  • 1
George Baker
  • 1,207
  • 9
  • 13
  • Reference - https://github.com/aosp-mirror/platform_frameworks_base/blob/master/services/core/java/com/android/server/notification/NotificationManagerService.java#L381-L382 – Shivam Pokhriyal Dec 27 '22 at 07:22
4

There are only these two constants related to Toast

http://developer.android.com/reference/android/widget/Toast.html#LENGTH_LONG

Why would you want to know their values though? You should always use the constants instead.

Zharf
  • 2,638
  • 25
  • 26
  • 3
    He's probably thinking he can set the duration to an arbitrary number of milliseconds. He cannot. – Earl Aug 08 '11 at 23:03
  • @Earl : yes I want to show toast for some arbitrary time.Is it possible? – CoDe Aug 09 '11 at 10:57
1

LENGTH_SHORT & LENGTH_LONG are mapped to time interval of 1 Second (1000mS) & 5 Seconds (5000mS) respectively,

To see this you need to dig into the AOSP source code of Toast. You can see in the Toast class time interval is decided based on the FLAG

mParams.hideTimeoutMilliseconds = mDuration == Toast.LENGTH_LONG ? LONG_DURATION_TIMEOUT : SHORT_DURATION_TIMEOUT;

where

 static final long SHORT_DURATION_TIMEOUT = 5000;
  static final long LONG_DURATION_TIMEOUT = 1000;

Reference: https://android.googlesource.com/platform/frameworks/base/+/f4bed684c939b0f8809ef404b8609fe4ef849263/core/java/android/widget/Toast.java

Hitesh Sahu
  • 41,955
  • 17
  • 205
  • 154
  • Wrong reference. The actual values are here https://github.com/aosp-mirror/platform_frameworks_base/blob/master/services/core/java/com/android/server/notification/NotificationManagerService.java#L381-L382 – Shivam Pokhriyal Dec 27 '22 at 07:22
1

They are one and zero as detailed in the Toast documentation. They are the only two values and no others are possible. There is an "indefinite toast hack", but I would not use an application that used it.

Earl
  • 791
  • 4
  • 9