Module 'Toybox.Graphics' not available to 'Background'

Hi,

I am trying to set up a background process for my app, with the intention to prompt the user to start the app. This is my ServiceDelegate class (more or less directly taken from the BackgroundTimer sample app:

using Toybox.Background as Bg;
using Toybox.System;

(:background)
class BackgroundServiceDelegate extends System.ServiceDelegate {

  function initialize() {
   ServiceDelegate.initialize();
  }

  // Prompt the user to start the app
  function onTemporalEvent() {

    Bg.requestApplicationWake("Start the app?");

    Bg.exit(true);
  }
}

When I run the app - even if I am not actually using this class, I get this error (in the Bg.exit(true) line):

Error: Permission Required
Details: Module 'Toybox.Graphics' not available to 'Background'

The problem is not with Bg.exit (true). Even if I remove that line, I get the same error (this time in the Bg.requestApplicationWake line).

By the way, the 'Background' Permission is set in the manifest file.

Does anyone have an idea why I get this error?

  • Are you sure that's where you get the error?  If you comment out the requestApplicationWake() do you still get it?  Which device, which SDK, and is it in the sim or on the actual device?

  • Thanks for your comment, Jim.

    Answers to your questions:

    1. Yes, I am sure

    2. After commenting out all lines within the function 'onTemporalEvent()', I get the same error on the line 'function onTemporalEvent()'

    3. Tried several Devices in the simulator: vivoactive 4 (SDK 3.1), Venu (SDK 3.1, and 3.2), D2 Charlie (SDK 2.4)

    4. Tried only the simulator as yet

    EDIT: and, by the way, I am not getting the error when running the BackgroundTimer sample (with D2 Charlie, SDK 2.4, in simulator, in Eclipse)

  • If you comment out everything in onTemporalEvent do you still get it?

    With  a background, there are a number of things in AppBase that also run in the background - Initialize(), onStart(). onStop(). and getServiceDelagate().

    Are you referencing Graphics in any of those?

  • My answers:

    1. Yes, after commenting out everything in onTemporalEvent, I still get the same error.
    2. My app class (which extends AppBase) doesn't directly reference the Graphics module, but it instantiates classes like the View class, which does refer to Graphics
    3. But, the error appears even after removing all references to 'Background' in the app class (including the :background tag)

  • you only want to use the view in getInitialView(), and not in things like initialize()  or onStart() for your AppBase. 

    If you commented everything out in onTemporalEvent() you're getting the error in something related to running that

  • My answer:

    In fact, I still get the error in onTemporalEvent(), after having commented out everything there (in the line 'function onTemporalEvent()) .

    But I'll try to move all instantiations of classes which refer to Graphics in my app class to getInitialView - see what happens.

    I'll write an update after I did that.

    Thanks up to this point, Jim.

  • Hi Jim,

    Yes, the problem was that I instantiated a number of classes in the onStart() method of the app which referred to Graphics. When I removed those instantiations, the error disappeared.

    Thanks a lot!