如何在一定的时间限制后调用另一个活动 [英] How to call another activity after certain time limit

查看:79
本文介绍了如何在一定的时间限制后调用另一个活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为一个活动调用另一个活动提供时间限制。我想通过给定一些时间限制来调用另一个活动(Ex将A类调用到B类)。我使用了alarmManager,但我的应用程序也不可能使用线程,每当我给Thread.sleep它就不会执行动作直到睡眠结束。我不知道该怎么做这个过程。任何人都可以给出给课堂时间限制的想法。

How to give time limit for calling one activity to another activity. I want to call another activity (Ex calling A class to B class) by given some time limit. I used alarmManager, but it is not possible for my application also i used threading, whenever i give Thread.sleep it will not perform action till the sleep getting end. I am not sure how to do this process. can anyone give a idea of giving time limit to calling a class.

推荐答案

你可以使用计时器并添加一个特定的 TimerTask 延迟。

You could use a Timer and add a TimerTask that is executed after a specific delay.

这是一个或多或少完成的例子:

Here is a more or less completed example:

Timer timer = new Timer();
timer.schedule(new TimerTask() {

   public void run() {

      //here you can start your Activity B.

   }

}, 10000);

上面的例子在10秒内执行一个新的TimerTask。在TimerTask中,您可以覆盖run方法。在run方法中,您可以开始新活动。在延迟之后执行run方法。在这个例子中它是10'000毫秒。

The example above executes a new TimerTask in 10 seconds. Inside the TimerTask you can override the run method. In the run method you can start your new activity. The run method is executed after the delay. In this example it is 10'000 milliseconds.

这篇关于如何在一定的时间限制后调用另一个活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆