一段时间后关闭活动 [英] close an activity after some time

查看:104
本文介绍了一段时间后关闭活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作骰子滚动应用程序,并且我想运行一个活动,该活动在按下按钮时显示结果图像,并在几秒钟后将其关闭.那我该怎么办呢?

I'm trying to make a dice rolling app and I want to run an activity which displays an image of the result when a button is pressed and close it after a few seconds. So how can I do this?

也许还有另一种方法可以在我的活动顶部显示图像而无需调用新活动?我不确定.

Maybe there's another way to display an image on top of my activity without calling a new activity? I'm not sure.

我已经阅读了一些有关计时器的内容,但我不太了解.而且我知道人们会告诉我让用户点击以关闭窗口,但是对于这个应用程序,我确定我希望它自动消失.

I've read some things about timers but I don't really get it. And I know people will tell me to let the user tap to dismiss the window but for this app I'm sure I want it gone automatically.

推荐答案

您可以使用:

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

        @Override
        public void run() {

                    image.setVisibility(View.GONE);
                    // If you want to call Activity then call from here for 5 seconds it automatically call and your image disappear....
        }
 }, 5000);

这篇关于一段时间后关闭活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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