Toasts are used in android to display Notifications. When .show() method is called they fade-in and stay for a while and fade-out depending upon what time in milliseconds we set for a Toast using setDuration() method.
We can only specify two values for the duration of Toast those are
- LENGTH_SHORT
- LENGTH_LONG
Do you know that even if we can set any integer value to setDuration(), the toast message will only be displayed for 1.5secs (ie Shot period) or 3secs (long period).
Both of these variables are Flags with value 0 and 1 respectively.
The reason if you see: NotificationManagerService.java code which is called to display Toast,
private void scheduleTimeoutLocked(ToastRecord r, boolean immediate)
{
Message m = Message.obtain(mHandler, MESSAGE_TIMEOUT, r);
long delay = immediate ? 0 : (r.duration == Toast.LENGTH_LONG ? LONG_DELAY : SHORT_DELAY);
mHandler.removeCallbacksAndMessages(r);
mHandler.sendMessageDelayed(m, delay);
}
Where,
private static final int LONG_DELAY = 3500; // 3.5 seconds
private static final int SHORT_DELAY = 2000; // 2 seconds
Hence there is no way you can change the value of LENGTH_LONG or LENGTH_SHORT. The only way to display Toast for a longer period is through some java code tweaking!
- Android Error Unexpected cast to Button: layout tag was FrameLayout
- ADT quit unexpectedly error on Mac OSX Android Eclipse SDK
- Parsing Data for android-21 failed unsupported major.minor version 51.0
- Android Studio Ctrl Shift o auto import not working
- java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
- Android : How to make TextView Scrollable
- This class should be public (android.support.v7.internal.widget.ActionBarView.HomeView) Lint Error
- Integrating Android Facebook SDK 3.17.2 Tutorial
- Android R Cannot Be Resolved To A Variable
- Android : Exception raised during rendering: action_bar API 22
- How to take screenshot on Android
- Read Text file from SD Card : Android Programming
- How to make Android EditText not editable
- Your Android SDK is out of date or is missing templates. Please ensure you are using SDK version 22 or later.
- The declared package does not match the expected package Eclipse
- Can't Run SDK Manager find_java.bat issue
- What is Android Toast.LENGTH_SHORT and Toast. LENGTH_LONG durations
- Android Emulator Soft Back button action using Computer keyboard
- Multiline EditText in Android Example
- Use 5G Network on Android Emulator
- Make Android TextView Clickable like Buttons
- How to empty trash in Android Device
- Android : Execute some code after back button is pressed
- Disable Fading Edges Scroll Effect Android Views
- How To Disable Landscape Mode in Android Application
- Test internet speed using macOS Terminal command - MacOS
- [Solved] Dynamic Web Module 3.0 requires Java 1.6 or newer Mac OSX - Mac-OS-X
- Save cURL Command Output to a external file - cURL
- [Android Studio] Could not automatically detect an ADB binary - Android-Studio
- How to Convert CSV file to SQL Script using Notepad++ - NotepadPlusPlus
- [Solved] SharePoint System.IO.FileNotFoundException was unhandled - SharePoint
- How to check if a String contains substring or a word using javaScript - JavaScript
- Disable Control Scroll Zoom-in and Zoom-out in Notepad++ - NotepadPlusPlus