Android simply encapsulates JQuery-like asynchronous requests

Source: Internet
Author: User

In android development, asynchronous request data is often used. handler or AsyncTask is usually used. It is troublesome to use handler with message. The AsyncTask thread pool only allows 128 threads to work, there will be overflow problems (of course, there will not be so many threads working at the same time) So I wrote this code and looked at it with high fingers!

01    02     03    04    05    06    07    08    09    10     11    12    13    14    15     16     17     18        19           String KEY = "key"20          String TAG = "JQuery"21            N = 5;22           Executor worker = Executors.newFixedThreadPool(N);23           Handler handler = 2425             26                TaskListener listener =27                Object result =28                (listener !=293031323334        35        3637        38           execute( String url,39            worker.execute(4041                 42                    String result = 43                    44                        result =45                    } 464748                    49                    Message msg = 50                    Bundle data = 515253                    msg.obj =5455565758        59        60          61             (worker !=  && worker 62                ExecutorService es =63                 (!6465666768        69         70             7172        77          78            79              String get(String url) 80                InputStream inputStream = 81                StringBuilder strBuilder = 82                BufferedReader reader = 83                 (String s = reader.readLine(); s != ; s =8485                8687                88899001    02    JQuery.execute("http://weather.news.qq.com/inc/minisite_125.js"0304                     05                        TextView t =  TextView(TaskDemoActivity.0607                        LinearLayout layout =080910                });

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.