gpt4 book ai didi

android - Ice Cream Sandwich 上的线

转载 作者:行者123 更新时间:2023-11-29 00:39:35 27 4
gpt4 key购买 nike

我在 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;
}

}

最佳答案

尝试在开始新 Activity 后调用 finish()。另外,为什么要在线程上调用 stop() ?一旦开始新 Activity ,它将停止。这是我已经写过的例子,随便改:

            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);

关于android - Ice Cream Sandwich 上的线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10296914/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com