我不断收到与 splashscreen.java 中的 Thread.stop() 相关的错误。我对此很陌生,并且知道已弃用的 Thread.stop() 但有人可以解释一下我在这里做错了什么,谢谢..
java.lang.UnsupportedOperationException
at java.lang.Thread.stop(Thread.java:1076)
at java.lang.Thread.stop(Thread.java:1063)
at com.dapp.d.SplashScreen$4.run(SplashScreen.java:88)
这是 splashscreen.java 的完整源代码
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RelativeLayout;
public class SplashScreen extends Activity {
private boolean active = true;
private int splashTime = 3000;
private boolean clickFlag = true;
private Thread splashTread = null;
private Button btnHelp;
private Button btnAboutUs;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
RelativeLayout relativeLayout = (RelativeLayout)findViewById(R.id.splashRelativeLayout);
relativeLayout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Uri uri = Uri.parse("http://www.exmaple.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});
btnAboutUs = (Button)findViewById(R.id.btnAboutus);
btnHelp = (Button)findViewById(R.id.btnHelp);
try{
btnAboutUs.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
clickFlag = false;
splashTread.stop(); <<<<<<<<<<<<<<<<<<< line 49
Intent intent = new Intent();
intent.setClass(getApplicationContext(), AboutUs.class);
startActivity(intent);
SplashScreen.this.finish();
}
});
btnHelp.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
clickFlag = false;
splashTread.stop(); <<<<<<<<<<<<<<<<<<< line 63
Intent intent = new Intent();
intent.setClass(getApplicationContext(), HelpActivity.class);
startActivity(intent);
SplashScreen.this.finish();
}
});
splashTread = new Thread() {
@Override
public void run() {
try{
int waited = 0;
while(active && (waited < splashTime)) {
sleep(100);
waited += 100;
}
} catch(InterruptedException e) {
// do nothing
}finally {
if(clickFlag){
Intent intent=new Intent();
intent.setClass(getApplicationContext(), SearchWord.class);
startActivity(intent);
finish();
stop(); <<<<<<<<<<<<<<< line 88
}else{
finish();
stop();
}
}
}
};
splashTread.start();
}catch (Exception e) {
// TODO: handle exception
}
}
}