Add the following configuration to the features attribute in the manifest.json file:
{"name": "system.resident"} 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') Item | Description |
|---|---|
Applicable devices | Mobile phones and tablets |
Applicable regions | Global |
API | Description |
|---|---|
Sends an app to the background. | |
Stops an app from running in the background. |
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: ' '
}) Description
Stops an app from running in the background. The implementation is currently empty.
Sample code
resident.stop()
<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.
