开发者

HttpClient with tabhosts

开发者 https://www.devze.com 2023-03-27 03:47 出处:网络
I have an application with TabHost with few tabs and in each tab I am displaying some web-page getting it from the server using HttpClient. Is it a good practice to open and instantiate a n开发者_运维

I have an application with TabHost with few tabs and in each tab I am displaying some web-page getting it from the server using HttpClient. Is it a good practice to open and instantiate a n开发者_运维百科ew HttpClient on every tab?


If you display a different web page in each tab, I'd go with one HttpClient per tab. But it really depends on what your exact requirement. For example, if you do not wish to update a tab while it is not being shown, you could reuse your HttpClient instance. That would, of course, place the onus of managing the state of the HttpClient between tab switches on you.


General rule:

It is always a good practice to re-use code and take modular approach. You can always create a separate class with static methods to satisfy your requirements instead of redoing it.

How does this set in your use would require you to paste some code as to what you mean by instantiating a new HTTPClient in each tab.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号