Toast-PhoneGap-Plugin: duration does not seem to accept values on "show" and "showWithOptions"methods (Android 8.0)

Expected behaviour

duration param should be adjustable and should allow to set different times e.g. 10000.

Actual behaviour

Neither of methods - show nor showWithOptions seems to keep toast alive for more than 3000 (3 secs).

I’m seeing this behaviour on

  • iOS device
  • iOS sim
  • Android device
  • Android sim

Hardware models

Samsung Galaxy S8

OS versions

Android 8.0

I’m not a dummy, so I’ve checked these

  • It happens on a fresh Cordova CLI project as well.
  • I’m waiting for deviceready to fire.
  • My JavaScript has no errors (window.onerror catches nothing).

So how can we reproduce this?

The below code snippet should suffice in reproduction steps:

     var waitToConfirm = 10000;
     if (!readyToExit) {
         readyToExit = true;
         // app exit has to be confirmed
         /* this snippet doesn't work as well
         window.plugins.toast.showWithOptions({
                 message: locale.getString("common.confrimAppExit"),
                  duration: waitToConfirm,
                  position: "center"
         });
         */
         window.plugins.toast.show(locale.getString("common.confrimAppExit"), waitToConfirm, 'center');
     } else {
         navigator.app.exitApp();
     }
     $timeout(() => {
         // simply reset readyToExit, since the user doesn't confirm app exit
         readyToExit = false;
      }, waitToConfirm);

Note: I had a chance to test the very same code snippet above on Xiaomi Redmi Note 4 / Android 7.0 and everything works just fine (the duration has been properly respected by the plugin). It seems the issue is due to OS version, since it is present on the emulator, which runs on Android 8.0 as well.

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Comments: 17 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Any idea how to move it forward? It was reported two months ago and basically, nobody gives an attention…

Thanks, mate. I see your point now and I do agree it is better to have a toast working on all Android versions. Anyway, as long as this issue specifically addresses a duration malfunctioning, let’s keep it open and hope at some point it will be fixed one way or another.

2.7.1 is now compatible with any Android version, but it may have implications for how long the Toast is shown. It is what it is.

it work for me: Toast.java, find private static final boolean IS_AT_LEAST_PIE = Build.VERSION.SDK_INT >= 28; replace with private static final boolean IS_AT_LEAST_PIE = Build.VERSION.SDK_INT >= 26;

guys - anyone able to at least elaborate on the issue? It’s been almost three months since I reported it and so far nobody gives any valuable feedback…