2012-04-24 91 views
2

我有上运行ICS 4.0.3线程上的冰淇淋三明治

我所做的APK线程问题,我已经安装了它无论在2.33 SE手机和谷歌Nexus S 4.0.3。

在SE上,apk运行并正在加载,因为它应该是。但是,在Nexus上,我收到了一个错误,我已经关闭它。但是我看到后面的程序正在运行。 我试图从代码中删除线程(加载屏幕,闪屏图片)并在Nexus上再次运行它,并且它可以运行。所以我发现我的问题是在线程上,onCreate线程开始。它从2.33到4.0.3有什么不同?

package my.LigTv.Browser; 

import android.app.Activity; 
import android.app.ProgressDialog; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.MotionEvent; 
import android.webkit.WebView; 
import android.app.AlertDialog; 
public class LigTVBrowserActivity extends Activity { 
/** Called when the activity is first created. */ 


WebView mWebView; 
AlertDialog alertDialog; 
protected boolean _active = true; 
protected int _splashTime = 3000; // time to display the splash screen in ms 
int progress = 0; 


@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.splash); 



    final Activity activity = this; 

    final ProgressDialog progressDialog = new ProgressDialog(activity); 
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); 
    progressDialog.setMessage("Please wait for the applet to load"); 

    progressDialog.show(); 
    progressDialog.setProgress(0); 
    activity.setProgress(progress * 1000); 

    progressDialog.incrementProgressBy(progress); 

    if(progress == 100 && progressDialog.isShowing()) 
     progressDialog.dismiss(); 



    Thread splashTread = new Thread() { 
     @Override 
     public void run() {     
      try { 
       int waited = 0; 
       while(_active && (waited < _splashTime)) { 
        sleep(100); 

        if(_active) { 
         waited += 100;              
         } 
       } 
      } catch(InterruptedException e) { 
       // do nothing 
      } finally { 
       finish(); 
       startActivity(new Intent("my.LigTv.Browser.Starter")); 
       stop(); 
      } 
     } 
    }; 
    splashTread.start(); 
}  

@Override 
public boolean onTouchEvent(MotionEvent event) { 
    if (event.getAction() == MotionEvent.ACTION_DOWN) { 
     _active = false; 
    } 
    return true; 
} 

} 
+1

你能告诉我们从发生错误的堆栈跟踪? – 2012-04-24 11:28:22

+0

我可以上传这个给你吗? – Tirolel 2012-04-24 11:41:48

+0

@LeythHisham编辑你的问题并追加它 – zapl 2012-04-24 11:53:43

回答

1

开始尝试新的活动后,呼叫finish()。另外,为什么你在线程上调用stop()?一旦它开始了新的活动,它就会停止。这是我已经写了一个例子,改变你的愿望:

  Runnable r1 = new Runnable(){ 
       public void run(){ 
        new Handler().postDelayed(new Runnable(){ 
         @Override 
         public void run(){ 
          startActivity(new Intent(Splash.this,Main.class)); 
          overridePendingTransition(R.anim.fade_out, R.anim.fade_in); 
          finish(); 

         } 
        }, waitTime); 
       } 
      }; 
      runOnUiThread(r1); 
+0

更不用说'stop()'已被弃用,不应该被使用。 – Jave 2012-04-24 11:40:16

+0

ty非常多,我fixet实际上与我自己的代码,但你是正确的我不知道为什么我键入停止(),我删除它,现在其工作在4.0.3非常感谢! – Tirolel 2012-04-24 17:17:14

0

should't这是在UI线程..

 runOnUiThread(new Runnable(){ 
       finish(); 
       startActivity(new Intent("my.LigTv.Browser.Starter")); 
       stop(); 
}); 
1

我遇到了同样的问题,我跟另一个代码固定它作为快速修复:

private Timer myTimer; 
private int x=0; 
private int interval=2500; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.splash); 

    myTimer = new Timer(); 
    myTimer.schedule(new TimerTask() { 
     @Override 
     public void run() { 
      TimerMethod(); 
     } 

    }, 0, interval); 

} 

private void TimerMethod() 
{ 
    this.runOnUiThread(Timer_Tick); 
} 

private Runnable Timer_Tick = new Runnable() { 
public void run() { 
    if(x==1) 
    { 
     SplashActivity.this.finish(); 
     startActivity(new Intent(SplashActivity.this,LoginActivity.class)); 
    } 
    x++; 
} 
}; 

但是,如果没有进度条,

如果你想这样做,当用户点击启动画面时,他会进入下一个活动,可以通过取消计时器并完成飞溅活动并转到其他活动来完成。

相关问题