views:

35

answers:

2

This is my onCreate method of my first activity of my app. It initalizes all Widgets and then starts a Thread to load model data from the internet. In some cases, when the network is really slow or not responding, the "initializeModelThread" seems to take the whole CPU and doesnt allow the onCreate Methode to finish.

In one case I saw that Log.v("Time...) was called after 300 ms, but the screen remained black for about 20 seconds until a HttpException stopped the initalizeModelThread. You already can see that I set the Priority of the Thread to low.

Would the use of AsyncTask help in this case? Do u have any other thoughts about that issue?

public void onCreate( Bundle savedInstanceState ) {
        super.onCreate(savedInstanceState);

        Long time = System.currentTimeMillis();

        initializeWidgets();

        Thread threadInstance = new Thread(initializeModelThread);
        threadInstance.setPriority(Thread.MIN_PRIORITY);
        threadInstance.start();

        Log.v("Time", "Difference from start " + Long.toString(System.currentTimeMillis() - time));

      }
A: 

AsyncTask would not make a difference here.

Instead of creating the thread on the onCreate() method, do it on the onStart() method.

Macarse