在我的应用程序中,我创建了一个SplashScreen
将 b 显示 5 秒的 a,然后根据存储在 Preference 文件中的值执行 if else case。如果首选项文件包含值,则AsyncTask
代码将运行,否则将加载登录表单。当我尝试运行我的应用程序时。该线程将在意图的帮助下进入登录表单,但是当涉及到AsyncTask
我的应用程序时,会显示强制关闭错误消息。
这是我的SplashScreen
代码:
public class SplashScreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splashscreen);
Thread timer = new Thread()
{
public void run()
{
try
{
sleep(5000);
}
catch(InterruptedException e)
{
e.printStackTrace();
}
finally
{
if(GoGolfPref.getEmail(SplashScreen.this)!=null && GoGolfPref.getPass(SplashScreen.this)!=null)
{
new LoadingScreen(SplashScreen.this, SplashScreen.this).execute("login_page", Login.url+GoGolfPref.getEmail(SplashScreen.this)+"/"+GoGolfPref.getPass(SplashScreen.this));
}
else
{
Intent in = new Intent(SplashScreen.this, Login.class);
startActivity(in);
finish();
}
}
}
};
timer.start();
}
}
这是我得到的错误:
08-29 07:25:58.040: E/AndroidRuntime(2365): FATAL EXCEPTION: Thread-10
08-29 07:25:58.040: E/AndroidRuntime(2365): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
08-29 07:25:58.040: E/AndroidRuntime(2365): at android.os.Handler.<init>(Handler.java:121)
08-29 07:25:58.040: E/AndroidRuntime(2365): at android.app.Dialog.<init>(Dialog.java:101)
08-29 07:25:58.040: E/AndroidRuntime(2365): at android.app.AlertDialog.<init>(AlertDialog.java:63)
08-29 07:25:58.040: E/AndroidRuntime(2365): at android.app.ProgressDialog.<init>(ProgressDialog.java:80)
08-29 07:25:58.040: E/AndroidRuntime(2365): at android.app.ProgressDialog.<init>(ProgressDialog.java:76)
08-29 07:25:58.040: E/AndroidRuntime(2365): at com.pnf.gogolf.LoadingScreen.<init>(LoadingScreen.java:130)
08-29 07:25:58.040: E/AndroidRuntime(2365): at com.pnf.gogolf.SplashScreen$1.run(SplashScreen.java:32)
如何让这个工作?
提前致谢...