Skip to content

Headless support for Android #185

@Angelk90

Description

@Angelk90

Feature Description

Add support on Android to allow background processes to run that can respond to events and updates even when the app interface is not active.

import { AppRegistry } from 'react-native';
import { updateAndroidWidget } from '@use-voltra/android-client';
import CardWidget from './CardWidget';

const BackgroundTask = async (data) => {
  try {
    const response = await fetch(
      'https://api.com/...'
    );

    if (!response.ok) {
      throw new Error(`HTTP ${response.status}`);
    }

    const results = await response.json();

    console.log('Results:', results);

    await updateAndroidWidget('card_widget', [
      {
        size: { width: 300, height: 200 },
        content: <CardWidget json={results} />,
      },
    ]);

    console.log('Widget update');
  } catch (error) {
    console.error('Error task headless:', error);
  }
};

AppRegistry.registerHeadlessTask(
  'BackgroundTask',
  () => BackgroundTask
);

Problem Statement

Improving the user experience by automatically performing tasks in the background, without requiring the app to be opened.

Proposed Solution

No response

Alternatives Considered

No response

Current Library Version

1.4.1

Implementation

  • I would be willing to submit a pull request for this feature

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions