Using Cookies across Activities when using HttpClient

后端 未结 6 1860
孤独总比滥情好
孤独总比滥情好 2020-12-04 15:43

I\'m trying a simple app to read in the HTML of a website, and tranform it to create an easily readable UI in Android (This is an exersize in learning android, not to make a

6条回答
  •  天涯浪人
    2020-12-04 16:31

    I suppose one of best thing is apply Singleton Pattern to your HTTPClient so you just have only one instance!

    import org.apache.http.client.HttpClient;
    import org.apache.http.impl.client.DefaultHttpClient;
    
    public class myHttpClient {
        private static HttpClient mClient;
        private myHttpClient() {};
        public static HttpClient getInstance() {
            if(mClient==null)
                mClient = new DefaultHttpClient();
            return mClient;
        }
    }
    

提交回复
热议问题