2012-02-04 44 views
1

我目前在市場上有一個簡單的應用程序,現在我試着在Android 4.0設備上安裝它。 但在我的Splashscreen關閉後失敗。我送的關係,並得到這個反饋:我的應用程序Splashscreen失敗的Android 4.0冰淇淋三明治

Crash 
java.lang.UnsupportedOperationException 
Thread.stop() 

java.lang.UnsupportedOperationException 
at java.lang.Thread.stop(Thread.java:1076) 
at java.lang.Thread.stop(Thread.java:1063) 
at com.lars.PSVWebView.SplashScreen$1.run(SplashScreen.java:35) 

這是代碼,自去年編輯:

package com.lars.DrinkRecOrder; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.os.Handler; 

public class SplashScreen extends Activity { 

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

     Handler handler = new Handler(); 
     handler.postDelayed(new Runnable() { 
      public void run() { 

       Intent intent = new Intent(); 
       intent.setClass(SplashScreen.this, DrinkRecOrderActivity.class); 
       }{ 
       /* start the activity */ 
       startActivity(new Intent("com.lars.DrinkRecorder.splashscreen.DrinkRecorderActivity")); 
      } 
     }, 500); 

    } 
} 

所以這是我的新代碼...沒有錯誤,但也不起作用,我的應用程序在啓動時崩潰。 順便說一句...相同的splashscreen代碼,不同的應用程序

回答

0

這是更好地回答和優雅的!

package com.lars.DrinkRecOrder; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.os.Handler; 

public class SplashScreen extends Activity { 

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

     Handler handler = new Handler(); 
     handler.postDelayed(new Runnable() { 
      public void run() { 

       /* start the activity */ 
       startActivity(new Intent("com.lars.DrinkRecOrder.splashscreen.DrinkRecOrderActivity")); 
      } 
     }, 5000); 

    } 
} 
1

Read the documentation on Thread.stop()

此方法已棄用。 ,因爲以這種方式停止線程是不安全的,可能會使應用程序和虛擬機處於不可預知的狀態。

拋出UnsupportedOperationException

+0

此外,絕對沒有理由在此時停止它。當執行從run()方法離開時,線程停止而不顯式停止它。 – harism 2012-02-04 17:29:42

2

您可以使用此方法:

Handler handler = new Handler(); 
     handler.postDelayed(new Runnable() { 
      public void run() { 

       Intent intent = new Intent(); 
       intent.setClass(SplashScreen.this, NextActivity.class); 
       } 
       /* start the activity */ 
       startActivity(intent); 
      } 
     }, SPLASH_SCREEN_TIME_IN_MILLISECONDS); 

我認爲這是遠遠超過Thread.sleep()

+0

我不確定我應該替換哪部分代碼,我根據教程做了這個 – 2012-02-05 00:34:33

+0

您可以複製我上面寫的代碼並粘貼到您的onCreate()方法中..您還必須更改NextActivity.class與您想要的活動類別(您想要在啓動屏幕後操作的類別)並設置毫秒數而不是SPLASH_SCREEN_TIME_IN_MILLISECONDS變量 – Cata 2012-02-05 09:14:48

+0

我編輯了最後一部分以向您展示我做了什麼,但仍然出現錯誤,我對不起,如果我打擾你.. – 2012-02-08 19:30:30

相關問題