android async splash screen not showing content view

in my app the main page contains, quite a few images to load on my upload manager activity so it can take a few seconds, depending on how many images there are. i planned on creating a splashscreen to do this loading while displaying an image which is not as bad as the default blank screen with title. i have done this, which should work and does, except the setcontentview() does run but does not display.

public class SplashScreen extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash_screen);


    load l=new load();
    l.execute(this);
}


class load extends AsyncTask<Activity, Object, Object>{

    @Override
    protected Object doInBackground(Activity... a) {
        // TODO Auto-generated method stub


    Log.i("ss", "splash");
        Intent intent = new Intent(a[0], UploadManager.class);
        startActivity(intent);
        a[0].finish();


        return null;
    }

}
}

does anybody have any suggestions? and feel free to ask for details i don't think i have explained it all too well.

edit:

thank you guys for the quick responses. however i believe the problem was that i wasn't using a splash screen for the correct purpose, the processes involved in:

 Intent intent = new Intent(a[0], UploadManager.class);
    startActivity(intent);
    a[0].finish();

seem to finish instantly, meaning the images in my onCreate method weren't executing until after the splash screen. what i did instead is changed the loading of my grid into an asynktask, as apposed to just doing my images in there.

i now have it loading fast with the images appearing after a few seconds. i shall be implementing a progress dialog of some sort.

anyone else with a similar problem should prioritize making the loading more efficient as i have.


You are passing Context as this in l.execute(this) and in class load you've passed Activity instance. You can do it in this way and it works like a charm for me

public class SplashScreen extends Activity{


    private static int SLPASH_TIME_OUT = 3000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

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

            @Override
            public void run() {
                // TODO Auto-generated method stub
                Intent i = new Intent(SplashScreen.this, MainActivity.class);

                startActivity(i);
                finish();
            }
        }, SLPASH_TIME_OUT);
    }
}

Override onPostExecute method in class load extends AsyncTask<Activity, Object, Object>{ class, which will run when your doInBackground method finishs image downloading. In onPostExecute you can open your next activity

like

protected void onPostExecute(Void unused) { Intent intent= new Intent(this, next.class); startActivity(intent); }

链接地址: http://www.djcxy.com/p/66794.html

上一篇: linux启动禁用显示/帧缓冲更新

下一篇: Android异步启动屏幕不显示内容视图