如何在Nativescript Android应用程序中实现空闲超时

时间:2020-06-23 05:51:43

标签: nativescript-angular

我正在用Nativescript angular构建一个Finacial应用程序。我需要一些参考,例如,如果该应用在设置了一些空闲超时后打开并在后台运行,则应将其重定向到我们指定的页面。我无法在Nativescript中获得正确的参考,任何人都可以为空闲超时添加解决方案。我已经检查了Nativescript扩展活动,但无法正确

1 个答案:

答案 0 :(得分:0)

您应该先阅读文档。您需要的是生命周期挂钩。

阅读:https://docs.nativescript.org/angular/core-concepts/application-lifecycle#use-application-events

import datetime
import apache_beam as beam

from apache_beam.options.pipeline_options import PipelineOptions
from apache_beam.io.gcp.bigtableio import WriteToBigTable
from google.cloud.bigtable import row


class MyOptions(PipelineOptions):
    @classmethod
    def _add_argparse_args(cls, parser):
        parser.add_argument(
            '--bigtable-project',
            help='The Bigtable project ID, this can be different than your '
                 'Dataflow project',
            default='bigtable-project')
        parser.add_argument(
            '--bigtable-instance',
            help='The Bigtable instance ID',
            default='bigtable-instance')
        parser.add_argument(
            '--bigtable-table',
            help='The Bigtable table ID in the instance.',
            default='bigtable-table')


class CreateRowFn(beam.DoFn):
    def process(self, key):
        direct_row = row.DirectRow(row_key=key)
        direct_row.set_cell(
            "stats_summary",
            b"os_build",
            b"android",
            datetime.datetime.now())
        return [direct_row]


def run(argv=None):
    """Build and run the pipeline."""
    options = MyOptions(argv)
    with beam.Pipeline(options=options) as p:
        p | beam.Create(["phone#4c410523#20190501",
                         "phone#4c410523#20190502"]) | beam.ParDo(
            CreateRowFn()) | WriteToBigTable(
            project_id=options.bigtable_project,
            instance_id=options.bigtable_instance,
            table_id=options.bigtable_table)


if __name__ == '__main__':
    run()

applicationOn(suspendEvent, (args: ApplicationEventData) => {
    setTimeout(() => {
        // do what you want after a certain amouont of time
        // don't
    }, 5000); 
});

别忘了您的应用可以强制关闭,因此您必须根据需要进行处理

相关问题