目录

Background Running

API Declaration

Add the following configuration to the features attribute in the manifest.json file:

{"name": "system.resident"}

Module Import

Add the following configuration to the script element on the page where the API will be called:

import resident from '@system.resident'

Or

const resident= require('system.resident')

Application Scope

Item

Description

Applicable devices

Mobile phones and tablets

Applicable regions

Global

Definition

API

Description

resident.start(OBJECT)

Sends an app to the background.

resident.stop()

Stops an app from running in the background.

[h2] resident.start(OBJECT) (1070+)

Description

Sends an app to the background. The implementation is currently empty.

OBJECT parameters

Parameter

Type

Mandatory

Description

desc

string

No

The value set here will not be displayed in the notification bar.

Sample code

resident.start({
    desc: ' '
})

[h2]resident.stop() (1070+)

Description

Stops an app from running in the background. The implementation is currently empty.

Sample code

resident.stop()

Demo

<template>
  <!-- Only one root node is allowed in template. -->
  <div class="container">
    <div class="item-container">
      <input type="button" class="btn" onclick="test_residentstart" value="resident start" />
    </div>
    <div class="item-container">
      <input type="button" class="btn" onclick="test_residentstop" value="resident stop" />
    </div>
  </div>
</template>

<style>
  .container {
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }
  .item-container {
    margin-top: 50px;
    margin-right: 30px;
    margin-left: 30px;
    flex-direction: column;
  }
  .btn {
    background-color: #0faeff;
    color: #ffffff; 
    width:400px;
    height: 100px;
    font-size: 50px;
    border-radius:15px;
  }

  .content { 
    border: 2px ;
    border-radius: 10px;
    text-align: center;
  }
</style>

<script>
  import resident from '@system.resident'
  import prompt from '@system.prompt';
  module.exports = {
    data: {
      info:''
    },
    onInit() {
      this.$page.setTitleBar({
        text: 'resident',
        textColor: '#ffffff',
        backgroundColor: '#007DFF',
        backgroundOpacity: 0.5,
        menu: true
      });
    },
    test_residentstart() {
      console.log("start running in the background");
         resident.start({
            desc: 'Backing up...30%'
        })
         prompt.showToast({
            message:  'start running in the background',
            duration: 2000,
            gravity: 'bottom'
            });
    },
    test_residentstop() {
         resident.stop()
         console.log("stop running in the background");
         prompt.showToast({
                message:  'stop running in the background',
                duration: 2000,
                gravity: 'bottom'
                });
    }
  }
</script>

The following figure shows the final effect.

Version Change History

Version

Date

Description

1070

2020-05-19

Added APIs to control the background running status of a quick app.