我在 ICS 4.0.3 上运行线程时遇到问题
我制作了 apk,并将其安装在 2.33 SE 手机和 Google 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;
}
}