Android : When I open the app it shows a white screen for a few seconds

chimbu picture chimbu · Sep 19, 2013 · Viewed 7.2k times · Source

When I open the app it shows a white screen for a few seconds for starting the service and all other things.

Can I avoid it by using a custom boot/loading screen loader or any other method is possible? and where I can put that code?

Help me, Thanks advance..

Answer

GrIsHu picture GrIsHu · Sep 19, 2013

Its happening because of you may be doing some the time consuming task in application UI thread. You have to do that task using Async or separate thread.

Whenever you are trying to do some time consuming tasks in your application's main UI thread it always blocks the UI.

You can also use the Handler. Android provides additional constructs to handle concurrently in comparison with standard Java. You can use the android.os.Handler class or the AsyncTasks classes.

The AsyncTask class encapsulates the creation of a background process and the synchronization with the main thread. It also supports reporting progress of the running tasks.

   class task extends AsyncTask<String, Integer, String> {
           @Override
    protected String doInBackground(String... params) {
             //your logic 
                 return null;
              }
            }

For more details Check