Toast based Android interview questions and answers

 What is Toast in Android?

Android Toast can be used to display information for the short period of time. A toast contains message to be displayed quickly and disappears after sometime.

2) When using setDuration() for a Toast, is it possible to set a custom length or at least something longer than Toast.LENGTH_LONG?

A toast can be displayed on the screen is defined by a flag as Duration. We can set duration Short or Long. The value for Short is 2.0 second and value for Long is 3.5 Second.

Context context = getApplicationContext();
Toast.makeText(context, "Testing Toast Message.", Toast.LENGTH_SHORT).show();

You can not directly change the duration of Toast Message which is showing in the show() method. But there is a workaround. You can use CountDownTimer Class or Handler Class to increase display time of Toast.

  • Schedule a countdown until a time in the future, with regular notifications on intervals along the way.
  • you need to create a new Window manager and show and hide the window for the desired duration using a handler

Comments

Popular posts from this blog

Jetpack Compose based Android interview and questions

Null safety based Kotlin interview questions and answers

CustomView based Android interview questions and answers