2013-03-27 51 views
2

我試圖做很多挖掘,但我無法解決我的這個問題。問題出在我的應用程序的啓動畫面上。除了Google Galaxy聯繫之外,所有設備/平板電腦上的splashscreen運行都沒有任何問題。而不是顯示splashscreen我看到一個空白的黑色屏幕,然後打開我的應用程序的主屏幕。谷歌Galaxy Nexus手機上的SplashScreen的奇怪問題

我檢查了下面的logcat,那裏有一個警告,看起來像罪魁禍首。

03-26 22:51:34.878: D/dalvikvm(26506): GC_FOR_ALLOC freed 30K, 1% free 8662K/8720K, paused 19ms, total 20ms 
03-26 22:51:34.894: I/dalvikvm-heap(26506): Grow heap (frag case) to 12.390MB for 4096016-byte allocation 
03-26 22:51:34.917: D/dalvikvm(26506): GC_FOR_ALLOC freed <1K, 1% free 12661K/12724K, paused 20ms, total 20ms 
03-26 22:51:34.925: D/dalvikvm(26506): GC_CONCURRENT freed <1K, 1% free 12661K/12724K, paused 2ms+1ms, total 15ms 
03-26 22:51:34.996: D/dalvikvm(26506): GC_FOR_ALLOC freed <1K, 1% free 12661K/12724K, paused 9ms, total 10ms 
03-26 22:51:35.058: I/dalvikvm-heap(26506): Grow heap (frag case) to 28.013MB for 16384016-byte allocation 
03-26 22:51:35.089: D/dalvikvm(26506): GC_FOR_ALLOC freed 0K, 1% free 28661K/28728K, paused 31ms, total 31ms 
03-26 22:51:35.128: D/dalvikvm(26506): GC_CONCURRENT freed <1K, 1% free 28661K/28728K, paused 12ms+2ms, total 36ms 
03-26 22:51:35.347: I/System.out(26506): true 
03-26 22:51:35.503: D/libEGL(26506): loaded /vendor/lib/egl/libEGL_POWERVR_SGX540_120.so 
03-26 22:51:35.535: D/libEGL(26506): loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so 
03-26 22:51:35.542: D/libEGL(26506): loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so 
03-26 22:51:35.917: D/OpenGLRenderer(26506): Enabling debug mode 0 
03-26 22:51:36.027: W/OpenGLRenderer(26506): Bitmap too large to be uploaded into a texture (1600x2560, max=2048x2048) 
03-26 22:51:36.871: V/CheatsDB.db(26506): db exists 
03-26 22:51:37.207: D/dalvikvm(26506): GC_FOR_ALLOC freed 6206K, 18% free 28757K/35028K, paused 14ms, total 14ms 

說「位圖太大無法上傳....」的行。我已經檢查了我的drawable,並沒有那麼大的圖像。啓動畫面使用的背景圖像是800 x 1280.這是目前我在所有設備上使用的唯一png圖像,啓動畫面在所有其他設備上都能正常工作。此外,logcat說圖像的大小看起來像1600 x 2560,我相信它是我的Nexus 10的分辨率。我沒有在任何地方添加任何具體尺寸的圖像。

我也張貼下面我SplashScreen.java文件代碼:

public class SplashScreen extends Activity { 

private final int SPLASH_DISPLAY_TIME = 1000; 
private Handler splashHandler = new Handler(); 
private Runnable splashRunnable; 
private final String firstLaunchCheck = "firstLaunchCheck"; 
SharedPreferences mPrefs; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    setContentView(R.layout.splash_screen); 

    mPrefs = PreferenceManager.getDefaultSharedPreferences(this); 

    final Boolean isFirstLaunch = mPrefs.getBoolean(firstLaunchCheck, false); 

    System.out.println(isFirstLaunch); 

    splashRunnable = new Runnable() { 
     @Override 
     public void run() { 

      if (!isFirstLaunch) { 

       SharedPreferences.Editor editor = mPrefs.edit(); 
       editor.putBoolean(firstLaunchCheck, true); 
       editor.commit(); 

       Intent mainIntent = new Intent(SplashScreen.this, 
         LookItUpTutorial.class); 

       mainIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); 

       startActivity(mainIntent); 
       SplashScreen.this.finish(); 


      } 
      else { 

       Intent mainIntent = new Intent(SplashScreen.this, 
         LandingPage.class); 
       startActivity(mainIntent); 

       SplashScreen.this.finish(); 
      } 
     } 
    }; 

    splashHandler.postDelayed(splashRunnable, SPLASH_DISPLAY_TIME); 
} 

// Remove any call back activities when back/home button is pressed on 
// SplashScreen 
@Override 
public void onPause() { 
    super.onPause(); 

    splashHandler.removeCallbacks(splashRunnable); 
    SplashScreen.this.finish(); 
} 
} 

也增加了我的佈局:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:background="@drawable/appbackground"> 

</LinearLayout> 

誰能給我我怎麼能去跟蹤的原因指針這個問題 ?我相信它與圖像大小警告有關,但是我沒有在我的源代碼中有任何大的圖像。任何幫助將不勝感激。

感謝您停下來閱讀這篇大文章。

+0

我建議你應該減少你的啓動畫面圖像到400x640,看看症狀是否改變。 – 2013-03-27 06:38:33

回答

2

根據您發佈的佈局,我不知道爲什麼Android會縮放您的圖像=)但通過一些工作,我們可以阻止它。

從您的佈局文件中刪除android:drawable併爲LinearLayout提供一個Id。然後用代碼自己加載drawable。

View mylinearlayout = findViewById(R.id.mylinearlayout); 
Options options = new Options(); 
options.inScaled = false; // explicitly disable all scaling 
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.appbackground, options); 
mylinearlayout.setBackground(new BitmapDrawable(bmp)); 
+0

這正是我所做的。 splashscreens背景圖像位於/ res/drawable目錄中。但問題依然存在。 – 2013-03-27 06:39:49

+0

我們可以看到佈局嗎? – 2013-03-27 06:40:47

+0

我已將佈局部分添加到帖子中。謝謝你的時間。 – 2013-03-27 06:43:17

1

我在幾個月前有同樣的問題。 經過幾個小時的調查。似乎圖片的大小是很大的(我使用的圖片的分辨率是1400x1600)。 然後我試圖重新縮放到600x800(質量仍然可以接受)然後它爲我工作。

p/s我在運行JB 4.1的Google Galaxy Nexus上遇到了這個問題。