如何在后Android的一段时间开始的活动?Android

2023-09-12 05:50:23 作者:旧街古人@

我正在开发,并在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

 
精彩推荐
图片推荐