2015-12-29 40 views
-1

我的啓動畫面出現在genymotion中,但在真實的Android設備上,屏幕僅顯示白色5秒。Android啓動畫面不可見

的佈局是:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity"> 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:src="@drawable/launchphone" 
     android:scaleType="fitXY"/> 

</RelativeLayout> 

該活動的代碼:

public class MainActivity extends Activity { 

    private DownloadAPITask task; 
    private String response; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     if(getResources().getConfiguration().isLayoutSizeAtLeast(Configuration.SCREENLAYOUT_SIZE_LARGE)){ 
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 
     }else{ 
      setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
     } 
     setContentView(R.layout.activity_main); 

     task = new DownloadAPITask(this, null, new Runnable(){ 
      @Override 
      public void run(){ 

       onAPIDownload(); 
      } 
     }); 
     task.execute(new APIRequest("http://my-site.com/api/", "request=asd")); 
    } 

    private void onAPIDownload(){ 
     StringBuilder strb = task.getResponse(); 
     if(strb == null){ 
      response = null; 
     }else{ 
      response = strb.toString(); 
     } 
     new Handler().postDelayed(new Runnable() { 
      @Override 
      public void run() { 
       launch(); 
      } 
     }, 2000); 
    } 

    private void launch(){ 
     Intent intent = new Intent(this, StartActivity.class); 
     intent.putExtra(StartActivity.API, response); 

     startActivity(intent); 
     finish(); 
    } 
} 

抽拉/ launchphone是位於在res .png文件/抽拉/未在任何的dpi的依賴性可繪製的位置,因爲它只是全屏縮放。我假設從真實設備上的漫長啓動時間開始,它就是閃屏,而不是呈現這個圖像,而只是顯示爲白色。

任何幫助將不勝感激。

+0

確保您啓動了Splash Activity,等待,終止它,並最終啓動主要活動 –

+0

您是否收到響應? – JUL2791

回答

0

你必須:import android.os.Handler;

new Handler().postDelayed(new Runnable){ 
    @Override 
    public void run() { 
     Intent intent = new Intent(getApplicationContext(), NextActivity.class); 
     startActivity(intent); 
     ThisActivity.this.finish(); 
    },1000); 
} 

你可以寫在閃屏的任何持續時間。 (在這種情況下,時間= 1000毫秒)