Skip to content

Background Action not performing the task #210

@Ahmad44452

Description

@Ahmad44452

I am trying to build an app for android, in which user can set time-slots and then according to those time-slots the wallpaper change throughout the day. One of the task would be to change the wallpaper in the background. For now, I have the following function that triggers on the click of the button. This function aims to set an image as the phones wallpaper after 15 seconds. It works completely fine, if the app is in foreground or is closed but available in recent apps.

  const setWallpaper = async () => {
    await BackgroundService.start(
      async () => {
        console.log('Starting Background Service');
        await delay(15000);
        console.log('Setting Wallpaper');
        await new Promise(resolve => {
          ManageWallpaper.setWallpaper(
            {
              uri: 'file:///storage/emulated/0/DCIM/Snapchat/Snapchat-118465363.jpg',
            },
            (res: any) => {
              console.log(res);
              resolve(res);
            },
            TYPE.HOME,
          );
        });

        console.log('Wallpaper set successfully');
      },
      {
        taskName: 'Set Wallpaper',
        taskTitle: 'ExampleTask title',
        taskDesc: 'ExampleTask description',
        taskIcon: {
          name: 'ic_launcher',
          type: 'mipmap',
        },
        color: '#ff00ff',
        linkingURI: 'yourSchemeHere://chat/jane',
      },
    );
    await BackgroundService.updateNotification({
      taskDesc: 'New ExampleTask description',
    }); 
  };

However, if I completely close the app (remove it from recent apps), the function works just partially. The string Starting Background Service and Setting Wallpaper before and after the delay are logged successfully. After this the ManageWallpaper.setWallpaper tries to change the wallpaper (ManageWallpaper class comes from this library). But neither does the wallpaper change nor the Wallpaper set successfully is logged and just the following two strings are logged.

BUNDLE  ./index.js 

WARN  No task registered for key Set Wallpaper1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions