文档管理中心
API参考快应用API基本功能后台运行

后台运行

接口声明

在manifest.json文件的 features属性中增加如下配置。

收起
自动换行
深色代码主题
复制
  1. {"name": "system.resident"}

导入模块

在调用接口页面的<script>部分增加如下配置。

收起
自动换行
深色代码主题
复制
  1. import resident from '@system.resident'

收起
自动换行
深色代码主题
复制
  1. const resident= require('system.resident')

使用限制

展开

限制条件

说明

适用终端

手机、平板

适用区域

全球

接口定义

展开

接口

描述

resident.start(OBJECT)

启动后台运行。

resident.stop()

停止后台运行。

resident.start(OBJECT)(1070+)

描述

启动后台运行。目前为空实现。

OBJECT参数

展开

参数

类型

是否必填

说明

desc

string

目前设置的值不会体现在通知栏。

示例代码

收起
自动换行
深色代码主题
复制
  1. resident.start({
  2. desc: ' '
  3. })

resident.stop()(1070+)

描述

停止后台运行。目前为空实现。

示例代码

收起
自动换行
深色代码主题
复制
  1. resident.stop()

Demo

收起
自动换行
深色代码主题
复制
  1. <template>
  2. <!-- Only one root node is allowed in template. -->
  3. <div class="container">
  4. <div class="item-container">
  5. <input type="button" class="btn" onclick="test_residentstart" value="resident start" />
  6. </div>
  7. <div class="item-container">
  8. <input type="button" class="btn" onclick="test_residentstop" value="resident stop" />
  9. </div>
  10. </div>
  11. </template>
  12. <style>
  13. .container {
  14. flex-direction: column;
  15. justify-content: center;
  16. align-items: center;
  17. }
  18. .item-container {
  19. margin-top: 50px;
  20. margin-right: 30px;
  21. margin-left: 30px;
  22. flex-direction: column;
  23. }
  24. .btn {
  25. background-color: #0faeff;
  26. color: #ffffff;
  27. width:400px;
  28. height: 100px;
  29. font-size: 50px;
  30. border-radius:15px;
  31. }
  32. .content {
  33. border: 2px ;
  34. border-radius: 10px;
  35. text-align: center;
  36. }
  37. </style>
  38. <script>
  39. import resident from '@system.resident'
  40. import prompt from '@system.prompt';
  41. module.exports = {
  42. data: {
  43. info:''
  44. },
  45. onInit() {
  46. this.$page.setTitleBar({
  47. text: 'resident',
  48. textColor: '#ffffff',
  49. backgroundColor: '#007DFF',
  50. backgroundOpacity: 0.5,
  51. menu: true
  52. });
  53. },
  54. test_residentstart() {
  55. console.log("start running in the background");
  56. resident.start({
  57. desc: ' 备份进度 30%'
  58. })
  59. prompt.showToast({
  60. message: 'start running in the background',
  61. duration: 2000,
  62. gravity: 'bottom'
  63. });
  64. },
  65. test_residentstop() {
  66. resident.stop()
  67. console.log("stop running in the background");
  68. prompt.showToast({
  69. message: 'stop running in the background',
  70. duration: 2000,
  71. gravity: 'bottom'
  72. });
  73. }
  74. }
  75. </script>

效果图如下:

版本更新说明

展开

版本

发布日期

描述

1070

2020-05-19

新增接口,用于控制快应用在后台运行。

在 API参考 中进行搜索
请输入您想要搜索的关键词