1

I've figured out how to get android to run some Java code on the systemwide BOOT_COMPLETED event. It's not clear to me what I need to do next to start my app in some form. As a novice android developer, I'm not even sure exactly if I can call into the JS side of the app at this point - is it even initialized?

Right now, on my personal device, the app crashes around this code:

            Context context = getApplicationContext();
            Intent myIntent = new Intent(context, BootUpHandlerService.class);
            context.startService(myIntent);

...on the startService call, I get a BackgroundServiceStartNotAllowedException.

I presume this means I need to call startForegroundService instead, but the android docs say that may not be possible with Android 12.

The docs also seem to suggest I can start a WorkManager task. Given all the code I've written to use WorkManager tasks actually does so from javascript through a 3rd party library, I have no clue how to even do that from Java. All of my code to prepare for the work I want to do in the background and initialize the tasks themselves is in the frontend, running in an expo/react-native context. Sure, poor practice, but I can refactor once I understand what I need to refactor it into.

While I appreciate what they are doing here as an end user who hates the numerous services running in the background on my phone, it does seem confusing for a novice android developer.

What should I do instead? How do I run JS without the frontend to schedule WorkManager tasks? The docs seem to say I can't even do that, not even with a "notification trampoline".

Alexander Riccio
  • 358
  • 2
  • 12
  • It's a more specific form of this question: https://stackoverflow.com/questions/47944721/start-an-app-automatically-on-device-start-with-react-native – Alexander Riccio Jul 26 '22 at 20:56
  • Do you want that the activity start running without user interaction or do you want to bring the React level up - e.g index.js listening for events? – Keselme Sep 11 '22 at 13:02

0 Answers0