views:

64

answers:

1

Threads Picture

I have no idea, but my app is stalling sometimes completely (not responding to touching the screen) I thought I was following all the rules for threading, but my app is apparently slowing down the Sprint EVO! I have never used an app as slow as my own. I don't get an ANR dialog, though I think I probably should get getting one. I have no idea how to make this application run like every other app I've ever used -- Not freezing. Is it not a good idea to have one HttpClient and keep a static reference to it for all Activities that want to use it? I used to create a new one each time, and thought that changing it to one sped it up. None of my AsyncTasks ever end. If I go to Activity A -> B -> C -> D the first time it will be smooth. I can press back but when I get back to A, its completely frozen, not responding to anything. That when I took that screenshot. I really have no clue what I am doing wrong. Should I manually kill my AsyncTasks on Activity.onPause()?

A: 

I'm not sure about your Activity freezing... it makes me think that you're getting into an infinite loop in onPreExecute or onPostExecute() of your AsyncTask, but who knows.

I do know, however, that you should be using a ThreadSafeClientConnManager if you're going to share your HttpClient between multiple threads.

    // Create the client.  We can cache and reuse this client because we're using a
    // ThreadSafeClientConnManager, which will create a pool of connections for us 
    // to use across multiple threads.
    HttpParams params = new BasicHttpParams();
    HttpConnectionParams.setSoTimeout(params, TIMEOUT);
    HttpConnectionParams.setConnectionTimeout(params, TIMEOUT);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(
            new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
    httpClient = new DefaultHttpClient(cm, params);
Neil Traft
I have been using a ThreadSafeClientConnManager, however I did not set a timeout. what is the best way to handle timing out for neccesary operations?
Aymon Fournier
I would recommend setting those timeout parameters. That way, if you hit the timeout then the HttpClient will return a proper `HttpResponse` with a 408 error code (the code for client timeout).
Neil Traft
I tried this but it caused more problems then before, Appreciate the effort though, and I am sure it is useful in some cases.
Aymon Fournier