2012-06-10 59 views
0

我使用代碼被髮布在堆棧溢出的android應用程序的啓動屏幕的代碼。我無法獲得輸出。這是代碼。在android中的飛濺屏幕不工作

package com.splash; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.os.Handler; 
public class SplashScreen extends Activity { 

     private static final int SPLASH_DISPLAY_TIME = 3000; 

     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.splash); 

      new Handler().postDelayed(new Runnable() { 

       public void run() { 

        Intent mainIntent = new Intent(Splashscreen.this, 
          MainActivity.class); 
        Splashscreen.this.startActivity(mainIntent); 

        Splashscreen.this.finish(); 
        overridePendingTransition(R.anim.mainfadein, 
          R.anim.splashfadeout); 
       } 
      }, SPLASH_DISPLAY_TIME); 
     } 
    } 
} 

這是splash.xml文件;

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"> 
<ImageView 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:src="@drawable/splash" /> 
</LinearLayout> 

請告訴我如何解決它。我也有淡入淡出的xml文件,用於啓動屏幕圖像。

在你的代碼
+0

「public class SplashScreen extends Activity {」double is typo error? –

回答

0

public class SplashScreen extends Activity {兩次..

使其單。

package com.splash; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.os.Handler; 
public class SplashScreen extends Activity { 

     private static final int SPLASH_DISPLAY_TIME = 3000; 

     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.splash); 

      new Handler().postDelayed(new Runnable() { 

       public void run() { 

        Intent mainIntent = new Intent(Splashscreen.this, 
          MainActivity.class); 
        Splashscreen.this.startActivity(mainIntent); 

        Splashscreen.this.finish(); 
        overridePendingTransition(R.anim.mainfadein, 
          R.anim.splashfadeout); 
       } 
      }, SPLASH_DISPLAY_TIME); 
     } 
    } 
+0

嘿,我檢查了它,並得到它。謝謝。 但是在顯示圖像之後,應用程序啓動(process.com.splash)意外停止,應用程序停止運行時出現錯誤。請再次嘗試。 有一個調用MainActivity類的意圖: - 意圖mainIntent = new Intent(Splashscreen.this, MainActivity.class); Splashscreen.this.startActivity(mainIntent); 但不能工作。請幫忙 – user1447105

0

確保將MainActivity添加到AndroidManifest.xml中。同時發佈來自logcat的異常堆棧跟蹤可以幫助很多。

0

很可能,您沒有'MainActivity'類。檢查它的名字是否正確。並確保它在正確的包裝並添加到清單。