如何在后Android的一段时间开始的活动? [英] How to start activity after some time in Android?

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

问题描述

我正在开发,并在Android应用我要开始另一个应用程序(我的第二个应用程序)。我做了以下code

I am developing and android application in that I want to start another application(my second application). I am doing the following code

 Intent i= new Intent();
 i.setComponent(new ComponentName("my second app package","my class name"));
 startActivity(i);

这是工作的罚款。

It is working fine.

我要隐藏3或5秒后,第二次申请,我在按照以下code

I want to hide the second application after 3 or 5 seconds for that I am following the below code

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

                @Override
                public void run() {
                    // TODO Auto-generated method stub
                    Intent i = new Intent("first app package","first app class name" );
                i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(i);
                }
            }, 5000);

但是,这code不工作如我所料只为我的第二个应用程序。但是,其他应用程序工作正常。相反,线程我也试过处理程序,alaram经理还没有sucess。请任何一个能帮助我在此。

But this code is not working as I expected only for my second application. But other applications are working fine. Instead thread I also tried Handler, alaram manager also no sucess. Please any one help me in this.

是我想要做的任何code的变化在我的第二个应用程序或什么是我的code中的问题?

Is I want to do any code change in my second application or what is the problem with my code?

感谢

推荐答案

您可以使用线程,但最主要的是你要调用finish()方法来结束当前的活动。

you can use thread but main thing is you have to call finish() method to finish current activity.

     Thread thread = new Thread( new Runnable() {
        @Override
        public void run() {
            try
            {
                   Thread.sleep(3000);

                }
                Intent intent = new Intent(1stActivity.this, SecondActivity.class);
                startActivity(intent);
            }
            catch (Exception e) {
                e.printStackTrace();
            }
            finally {
                finish();
            }
        }
    });

    thread.start();

在try块,我把视频下载(3000),你可以改变它做你的try块的工作

in the try block i put Thread.sleep(3000) you can change it do your work in try block

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

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