替代方法Thread.sleep代码Android中 [英] Alternative to Thread.sleep method in Android

查看:310
本文介绍了替代方法Thread.sleep代码Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个按钮点击后保存在我的文本框,以谷歌应用程序引擎输入的详细信息,调用该onClickListener后,我有一个启动一个新的活动,它显示我刚刚进入细节的意图。
这里是code此:

I have this button that when clicked saves the details entered in my textfields to Google App Engine, right after the call to that onClickListener, i have an intent that starts a new activity, which displays the details I just entered. Here is the code for this:

submitButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if(v.getId() == R.id.userDetailsCaptureButton) {
                new EndpointsTask().execute(getApplicationContext());
            }

            startActivity(userProfileDisplayIntent);
        }
    });

现在我希望能够以后做给 startActivity 呼叫前等待几秒钟新EnpointsTask()。执行(getApplicationContext )被调用。我读了使用视频下载导致冻结UI,因此不是最适合这一点。还有什么其他的选择有哪些?

Now i want to be able to wait for a couple of seconds before making a call to startActivity after new EnpointsTask().execute(getApplicationContext) has been called. I read that using Thread.sleep causes the UI to freeze and as such isn't best suited for this. What other options are there?

推荐答案

的解决方案是使用一个处理器与一个可运行和使用该方法的postDelayed'。例如:

The solution is to use a handler with a runnable and use of the method 'postDelayed'. Example:

new Handler().postDelayed(new Runnable() {
    public void run () {
        // Do delayed stuff!
    }
}, 5000L); //5 seconds delay 

这篇关于替代方法Thread.sleep代码Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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