THREAD WARNING: exec() call to BackgroundModeExt.foreground blocked the main thread for 41ms. Plugin should use CordovaInterface.getThreadPool(). #2

Hello everyone, I have this problem.

when I call cordova.plugins.backgroundMode.moveToForeground(); It always works for me the first time, then I enter another application, for example Facebook, and this message is displayed in the logcat, what is it due to or how can I solve it?

I am using: GitHub - FWiner/cordova-plugin-android-background-mode: cordova-plugin-android-background-mode

This is the code that Cordova use for open app for to foreground:

private void moveToForeground()
{
  Activity  app = getApp();
  Intent intent = getLaunchIntent();

  intent.addFlags(
  Intent.FLAG_ACTIVITY_REORDER_TO_FRONT |
     Intent.FLAG_ACTIVITY_SINGLE_TOP |
     Intent.FLAG_ACTIVITY_CLEAR_TOP);

  clearScreenAndKeyguardFlags();
  app.startActivity(intent);
}

Attached video of my problem with moveToForeground():

VIDEO SUMMARY:

  1. I have the app open, then I exit.
  2. when running postman a service is sent and the app is brought to the foreground (which is the correct way)
  3. then I leave the app and enter facebook. I run postman and the app doesn’t open in the foreground anymore (this is the bug I want to fix).

That’s just a warning cordova-android shows when a plugin takes more than 16 ms to execute a method.

You can get rid of it by using threading, but honestly, I think the threshold is too low and 16 ms (or 33/41 as your plugin is taking) is still a very low value and you should worry about that.

Hello @julio-ionic I just edited the post showing what is happening to me, can you please help me what is happening
Thanks.