Android同时运行

时间:2013-08-29 10:32:17

标签: android

这是我的代码:

protected void loadvide(Chan channel) {
        Rtmpdump dump = new Rtmpdump();
        dump.parseString(channel.getUrl());
        startActivity(new Intent(this,VideoViewDemo.class));
    }

代码有效,但我遇到了问题。

问题是,当我执行应用程序时,首先将此部分执行到我的代码:

Rtmpdump dump = new Rtmpdump();
            dump.parseString(channel.getUrl());

和第二部分:startActivity(new Intent(this,VideoViewDemo.class));不起作用,因为第二部分在完成第一部分时开始工作。

但我希望在启动应用程序时,代码的第一部分和第二部分同时执行。

1 个答案:

答案 0 :(得分:1)

您可以为此

使用异步任务
private class MyAsyncClass extends AsyncTask<URL, Integer, Long> {
     protected Long doInBackground(URL... urls) {
         //Do your task here
         Rtmpdump dump = new Rtmpdump();
        dump.parseString(channel.getUrl());
     }

     protected void onProgressUpdate(Integer... progress) {
         setProgressPercent(progress[0]);
     }

     protected void onPostExecute(Long result) {
         startActivity(new Intent(this,VideoViewDemo.class));
     }
 }

根据android.developer =&gt;检查此链接http://developer.android.com/reference/android/os/AsyncTask.html

检查这几个教程=&gt; http://www.vogella.com/articles/AndroidBackgroundProcessing/article.html