2 slaks SLaks 于 2013.08.23 11:22 提问

Android 的 Splash Screen不能运行

我开发一个 android 应用程序,当检查文件是否更新,程序启动时应该显示一个 Splash Screen。
如果文件不更新,它启动了一个 Async Task 来更新文件。问题是当文件实际上需要更新时,只显示 Splash Screen 的图像,否则,执行检查时会显示黑屏。
SplashScreen activity:

   public class SplashActivity extends Activity
   {
    private final static String placesFile = "places";
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_splash);
    }

    @Override
    protected void onResume()
    {
        super.onResume();

        if(!isFileUpdated()){
            new PlacesService(this).execute();
        }else{
            intentAndFinish();
        }

    }
    private void intentAndFinish() {
        finish();
        Intent mainIntent = new Intent(this, MainActivity.class);
        startActivity(mainIntent);  
    }

    /**
     * 
     * @return false if Places Data is too old
     */
    private boolean isFileUpdated() {
        int daysOld = 0;
        File f = new File(this.getFilesDir().getAbsolutePath() +"/"+placesFile);
        if(f.exists()){
            System.out.println("existe");
        }
        Date d = new Date();
        Date currentDate = new Date(System.currentTimeMillis());
        d.setTime(f.lastModified());
        if(currentDate.compareTo(d)>0)
            daysOld = determineDifferenceInDays(d, currentDate);
        return daysOld < Consts.PLACES_DAYS_OLD_QTY_PERMITTED?true:false;
    }
    private static int determineDifferenceInDays(Date date1, Date date2) {
        Calendar calendar1 = Calendar.getInstance();
        calendar1.setTime(date1);
        Calendar calendar2 = Calendar.getInstance();
        calendar2.setTime(date2);
        long diffInMillis = calendar2.getTimeInMillis() - calendar1.getTimeInMillis();
        return (int) (diffInMillis / (24* 1000 * 60 * 60));
    }

    public void onResultFromAsyncTask(boolean finished) {
        if(finished){
            intentAndFinish();
        }
    }
}

activity_splash.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">

    <ImageView android:src="@drawable/splash_es"
               android:layout_width="fill_parent"
               android:layout_height="fill_parent"
               />
</LinearLayout>
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!