Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
santiagovasquez opened this issue Jan 10, 2023 · 1 comment

Comments

@santiagovasquez
Copy link

santiagovasquez commented Jan 10, 2023

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?

Screen Shot 2023-01-09 at 8 50 25 PM

Attached video of my problem with moveToForeground():
https://drive.google.com/file/d/1SQJ-6FNQ2Nr0nZxw7JBYwhGkYt9D33R_/view

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).
@santiagovasquez
Copy link
Author

santiagovasquez commented Jan 13, 2023

I found a solution for this, and although I don't know if it is the correct one or not, but this saved my life.
make the next step:

  1. Add in the Manifest.xml the permission: <uses-permission android:name="android.permission.REORDER_TASKS" />
  2. I am using de plugin: https://github.com/FWiner/cordova-plugin-android-background-mode (It is almost the same but more updated)
  3. Open the file platform/android/app/src/main/java/de/appplant/cordova/plugin/background/BackgroundModeExt.java
  4. in this file add this code:

Screen Shot 2023-01-12 at 10 31 09 PM

`

   // start solution
  ActivityManager am = (ActivityManager) cordova.getContext().getSystemService(Activity.ACTIVITY_SERVICE);
  List<ActivityManager.RunningTaskInfo> rt = am.getRunningTasks(Integer.MAX_VALUE);
  for (int i = 0; i < rt.size(); i++)
  {
    if (rt.get(i).baseActivity.toShortString().contains("YOUR_PACKAGE_PROJECT")) {
      am.moveTaskToFront(rt.get(i).id, ActivityManager.MOVE_TASK_WITH_HOME);
    }
  }
  // end solution`

REORDER_TASKS
Allows an application to change the Z-order of tasks, in this case, prioritize your app.
https://developer.android.com/reference/android/Manifest.permission#REORDER_TASKS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant