在线程上启动活动 [英] Start Activity on a thread

查看:94
本文介绍了在线程上启动活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个飞溅活动。我想在progressStatus达到最大值时开始一个新的Activity。我的问题是我不知道在哪里可以找到开始意图。我的 IF语句出错。

I have a Splash Activity. and I want to start a new Activity when the progressStatus reach its max value. My problem is i dont know where to locate the start intent. I have an error on my IF statement.

    new Thread(new Runnable() {
        public void run() {
                while (progressStatus < 100) {
                progressStatus += 5;

                }   
                if (progressStatus == progressBar.getMax()) {
                        Intent intent = new Intent(".MENU");
                        startActivity(intent);
                    }
                // Update the progress bar and display the
                // current value in the text view
                handler.post(new Runnable() {
                    public void run() {
                        progressBar.setProgress(progressStatus);
                        textView.setText(progressStatus + "/"
                                + progressBar.getMax());
                    }
                });

                try {
                    // Sleep for 200 milliseconds.
                    // Just to display the progress slowly

                    Thread.sleep(200);

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

    }).start();

在我的清单上:

<activity
android:name="NewMainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
       <category android:name="android.intent.category.DEFAULT" />
       <action android:name=".MENU" />
</intent-filter>
</activity>

我的飞溅活动是 MainActivity Class ,然后 NewMainActivity类是第二个活动。

My Splash activity is MainActivity Class then NewMainActivity Class is the second activity.

推荐答案

尝试检查while循环就像这样

try to check the while loop as simply as this

new Thread(new Runnable() {
    @Override
    public void run() {
        while (progressStatus < 100) {
           progressStatus += 5;
           // Update the progress bar and display the 
           //current value in the text view
           handler.post(new Runnable() {
                @Override
                public void run() {
                   progressBar.setProgress(progressStatus);
                   textView.setText(progressStatus+"/"+progressBar.getMax());
                }
            });

            try {
               // Sleep for 200 milliseconds. 
               //Just to display the progress slowly
               Thread.sleep(200); 
               if (progressStatus == 100){
                   Intent intent = new Intent(".MENU");
                   startActivity(intent);
               }

            } catch (InterruptedException e) {
               e.printStackTrace();
            }
         } // while loop
      } // run()
  }).start();

然后在 Thread.sleep()下把你的条件。

then under the Thread.sleep() put your condition.

这篇关于在线程上启动活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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