Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I avoid a black screen before startup?

I created a loadpage with a background and a progress bar and when it finishes loading, it starts the main class but the loading screen is not showing up. It is just a black screen while it loads and then the main screen. I put all the work in the onResume and I also tried onStart with no luck

    @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.loadpage);
    //get rid of title bar
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setRequestedOrientation(1);

}

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

    words = WordList.sharedWordList(this);

    if(generatedLevels==null)
    {
        generatedLevels  = new ArrayList<PuzzleMZLen>();
    }
    if(!p.isAlive())
    {
        p.start();          
    }


    Intent i = new Intent(getApplicationContext(), Main.class);
    startActivity(i);

}

thanks in advance

like image 260
Robin Avatar asked Dec 16 '22 11:12

Robin


1 Answers

You have to use AsyncTask for this kind of work.Your layout is populated after the completion of the loading.So you are watching black screen.

Use onPreExecute of AsyncTask class to show the progress bar. And write loading code in the doInBackground method.

like image 154
Rasel Avatar answered Jan 04 '23 05:01

Rasel