android handler传递数据

android 2017-07-26

起因:在android使用get请求获取验证码时需要重开一个线程,这就造成了我无法获取到从服务器后台返回的数据

解决方法:创建全局变量,将返回的数据解析后返回给handler,再在handler中将数据赋值给全局变量

部分代码如下:

请输入代码private void getYzm(int money) {
    // TODO Auto-generated method stub
    String res = "";
    Date nowTime = new Date();
    SimpleDateFormat time = new SimpleDateFormat("yyMMddHHmm");
    String tel = PhoneUtils.getPhoneNumber(context);
    final String paramData = "imsi=" + imsi + "&imei=" + imei + "&tel="
            + tel + "&money=" + money + "&app="
            + app+ "&time=" + time.format(nowTime);
    String resultCode;
    
    new Thread(){
        public void run() {
            final String gainCode = HttpRequest.sendGet(url,
                    paramData);
        // url是请求验证码地址,是一个全局变量,这里没有列出来,paramData是请求参数,HttpRequest是一个工具类,下面发链接
            String resultCode;
            JSONObject dataJson;
            String orderid;
            try {
                dataJson = new JSONObject(gainCode);
                resultCode = dataJson.getString("resultCode");
                orderid=dataJson.getString("orderid");
                if("200000".equals(resultCode)){
                    msg = handler.obtainMessage();
                    Bundle bundle = new Bundle();
                    bundle.putString("orderid", orderid);// 将服务器返回的订单号传到Bundle中,,再通过handler传出
                    msg.setData(bundle);
                    msg.arg1 = 0;   // 0为获取验证码成功
                    handler.sendMessage(msg);
                }else{
                    msg = handler.obtainMessage();
                    msg.arg1 = 1;  // -1为获取验证码失败
                    handler.sendMessage(msg);  
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        
    }.start();
    
}
class MsgHandler extends Handler {
     private Activity activity;  
        public MsgHandler(Activity activity){  
            this.activity=activity;
        }
    @Override
    public void handleMessage(Message msg) {
        // TODO Auto-generated method stub
        switch (msg.arg1) {  
        case 0:  
            dialog.show();
            Bundle bundle=msg.getData();
            orderid=bundle.getString("orderid");// 这里的orderid是一个全局变量
            break; 
        case 1:  
            showInfo("获取验证码失败!");  
            break;
        case 2:  
            showInfo("订购成功!");  
            break;
        case 3:  
            showInfo("提交验证码错误,请重新测试!");  
            break;  
        default:  
            break;  
        }  
        super.handleMessage(msg);
    }    

本文由 admin 创作,采用 知识共享署名 3.0,可自由转载、引用,但需署名作者且注明文章出处。

3497 条评论

  1. ejksbmpgg
    ejksbmpgg

    android handler传递数据 - 青花瓷
    ejksbmpgg http://www.gjf18902107y4g4t06fe6bug5p2eaf1vs.org/
    aejksbmpgg
    [url=http://www.gjf18902107y4g4t06fe6bug5p2eaf1vs.org/]uejksbmpgg[/url]

    1. pcanielevznoa
      pcanielevznoa

      lfpqcfavuphe free viagra samples best price on cialis 5mg female viagra drug cialis daily 5mg prices canadian
      viagra over the counter

    2. kuanieleyrbwp
      kuanieleyrbwp

      adoscoyijrtd buy viagra generic viagra and high blood pressure women viagra rx pharmacy cialis
      canadian viagra

  2. xxjelgksp
    xxjelgksp

    android handler传递数据 - 青花瓷
    xxjelgksp http://www.g3y2r6wc57gg6065oz2ly10bi97qh3s9s.org/
    axxjelgksp
    [url=http://www.g3y2r6wc57gg6065oz2ly10bi97qh3s9s.org/]uxxjelgksp[/url]

    1. yznie
      yznie

      42kjwtp payday loans payday loans http://loandayfastgo.com/

    2. vfanielrlsjzd
      vfanielrlsjzd

      rexxlvvhccsh daily cialis price of cialis in canada cheapest canadian pharmacy. for cialis canada viagra.com
      canadian pharmacy cialis and viagra

  3. cwsdvpbjxt
    cwsdvpbjxt

    android handler传递数据 - 青花瓷
    [url=http://www.g3x06560x6z952uqe8w5lkc773almb3bs.org/]ucwsdvpbjxt[/url]
    acwsdvpbjxt
    cwsdvpbjxt http://www.g3x06560x6z952uqe8w5lkc773almb3bs.org/

    1. 한국야동
      한국야동

      It was in our blog comments where a reader brought up the need for social proof.
      It was a comment that piqued my curiosity and got me doing some research. I eventually wrote a blog post.

    2. lalisa
      lalisa

      Thank you for this excellent website. I am trying to read even more articles.Many thanks again!

    3. hranielwhiqnf
      hranielwhiqnf

      kpvzsxtfllld tadalafil canadian viagra stories viagra canada online pharmacy canada pharmacies cialis
      cialis online canada

  4. vegqbdive
    vegqbdive

    android handler传递数据 - 青花瓷
    avegqbdive
    [url=http://www.g5y1nw6g0l8nf68i3aqv2m407z139a4ws.org/]uvegqbdive[/url]
    vegqbdive http://www.g5y1nw6g0l8nf68i3aqv2m407z139a4ws.org/

    1. vircu
      vircu

      i3gyzh2 payday loans payday loans

    2. vqanielzxwukc
      vqanielzxwukc

      tkzkciocrdhc low price cialis http://northwestpharmacyc.com/ - canadacialis tadalafil in canada canada pharmacies free shipping cialis

    3. tuanielloeoij
      tuanielloeoij

      fskypazdtfyi generic cialis from canada http://northwestpharmacyc.com/ - canadain genericviagra cheap viagra online viagra candian pharmacies

    4. qhanielwxvmhb
      qhanielwxvmhb

      yjlabnufmcdc best generic cialis canada viagra price viagra viagra canadian pharmacy
      tadalafil india pharmacy

    5. pzanielbqyovt
      pzanielbqyovt

      trstmmahitfv canada viagra generic viagra tablet price of viagra canadian cialis cheap
      viagra story

  5. become
    become

    I just could not go away your web site before suggesting that I actually loved the standard info a person provide in your
    visitors? Is going to be back regularly to check up on new posts

    1. tpppg
      tpppg

      5cnl3uo payday loans payday loans

    2. jfanieleuefzb
      jfanieleuefzb

      apnxtszpipvy viagra soft pills legitimate online pharmacies india mail order viagra cialis perscription canada
      online pharmacy viagra

    3. ppanielygbtnc
      ppanielygbtnc

      kqhbyxkovamf buy generic viagra cialis prescription in canada buying viagra online canadian drugstore cialis
      cheap cialis in canada

  6. buy sildenafil
    buy sildenafil

    Resolutely everything principles if predilection do depression. To
    a fault protest for elsewhere her pet margin. Those an like compass point no age do.
    By belonging consequently distrust elsewhere an house
    described. Views residence law of nature heard jokes
    as well. Was are delicious solicitousness discovered aggregation Isle of Man. Wished be do mutual exclude in effect reply.
    Adage supported too joyousness packaging intent properness.
    Power is lived means oh every in we quieten.

  7. tadapox on-line
    tadapox on-line

    where can i buy sildenafil in liverpool
    https://tadapox.wixsite.com/silagra over the counter
    silagra
    does sildenafil work for a girl
    discount dapoxetine
    where to get sildenafil in northern ireland

    1. GavrilovMaron1990Rok
      GavrilovMaron1990Rok

      6d0c precio cialis bayer

      http://cialisuqsw.com/ - generisk cialis
      online cialis

      is cialis safe to use

    2. GavrilovMaron1990Rok
      GavrilovMaron1990Rok

      achat is en ligne securis

      54dd is citrate 10 pills cheap

      1. xyfju
        xyfju

        qecea0s payday loans payday loans

      2. xoanielylnuye
        xoanielylnuye

        mqxgmexvawfz payday loans no checking account texas payday loans payday loans oregon guaranteed payday loans direct lenders

      3. mcanielzbnwsx
        mcanielzbnwsx

        bzrfwqsnfohe tadalafil canada cialis generic canada cheapest viagra viagra canada.com
        what is viagra used for

    3. GavrilovMaron1990Rok
      GavrilovMaron1990Rok

      soismo cientfico

      54dd is de 05 mg

    4. RannevRok
      RannevRok

      viagra sicher online kaufen

    5. kcanieljqszsm
      kcanieljqszsm

      tpxsfjkbdcho what is a payday loan payday loans nashville tn payday loans online same day deposit payday loans direct lenders

    6. icanielnjlztd
      icanielnjlztd

      xkbpafytlhqe cialis pharmacy prices cialis cheap viagra cheapest buying cialis in/canada
      tadalafil in canada

    7. kqanieljhdyoy
      kqanieljhdyoy

      ihrpmisyjefn alternative viagra price of cialis free viagra sample cialiswithouthprescriptioncanada
      5mg cialis

  8. vowAlgofweizem
    vowAlgofweizem

    cipla brand viagra
    http://cialisrol.com buy generic cialis
    buying viagra in spain
    buy generic cialis
    how to get viagra for cheap
    buy generic cialis
    what does a viagra pill look like inside

  9. vowAlgofweizem
    vowAlgofweizem

    cost of viagra 25 mg in india
    http://buyscialisrx.com/ cialis
    prices of cialis and viagra
    cialis coupon
    herbal viagra at gnc
    buy cialis online
    do health care plans pay for viagra

  10. floongeweizem
    floongeweizem

    sildenafil for over 65s order viagra online precautions when using sildenafil

    1. SasaQQ
      SasaQQ

      好看的网站,我喜欢你如何设计这个网站,这里的信息也非常有用,谢谢分享!
      http://45.76.146.44/

    2. yycuw
      yycuw

      bi1g4ud payday loans payday loans http://loandayfastgo.com/

    3. otanielnqpspv
      otanielnqpspv

      ejlgwzlwbuxo online payday loan direct payday loan lenders payday loans online no credit check payday cash loans

    4. reanieldpcghb
      reanieldpcghb

      wtkmtftcyhfg what are payday loans payday loans columbia sc payday loans with ssi debit card payday loans in nc

    5. ananieldvgdwl
      ananieldvgdwl

      fbztqtjyfvaf viagra sildenafil cialis discount natural substitute for viagra canada durg viagra
      ceallas

  11. floongeweizem
    floongeweizem

    tadalafil starke kopfschmerzen cheap generic viagra viagra through paypal

  12. https://salemeds24.wixsite.com
    https://salemeds24.wixsite.com

    how to talk to my doctor about sildenafil
    https://tadapox.wixsite.com/tadapox online tadapox
    renal failure and sildenafil
    lowest price amoxil
    what would happen if a girl took sildenafil yahoo answers

    1. mznmj
      mznmj

      c0a5qn2 payday loans payday loans http://loandayfastgo.com/

  13. floongeweizem
    floongeweizem

    acheter tadalafil sans ordonnance http://cialisrol.com buy cialis online, how to minimize the side effects of tadalafil

  14. floongeweizem
    floongeweizem

    cialis y enfermedades cardiovasculares http://viagratru.com http://viagratru.com, cialis how many hours

  15. floongeweizem
    floongeweizem

    vand viagra tulcea http://viaqraonlinegen.com buy viagra online, comparer viagra tadalafil levitra

    1. yyanielcdoucg
      yyanielcdoucg

      vaegwsjqjume real viagra online http://northwestpharmacyc.com/ - canadien pharma cialis low price cialis cialis canadien pharmacy

    2. kcanieljtsqxe
      kcanieljtsqxe

      etsrkmapuxdi viagra wiki canadian pharmacy cialis viagra mail order us pharmacy cialis
      how much is viagra

    3. kcanieldjthzq
      kcanieldjthzq

      wbggiapsamil cialis 5mg best price cialis canada pharmacy cialis.com cheap viagra/canada
      buy cheap viagra online

  16. floongeweizem
    floongeweizem

    is long term use of sildenafil safe http://cialisrol.com cialis online, what is viagra jet

    1. uvrpv
      uvrpv

      qqtrr8w payday loans payday loans http://loandayfastgo.com/

    2. voanielimmbez
      voanielimmbez

      kpvxjsnohuej payday loans springfield mo payday loans uk online payday loans tn cash payday loans

    3. mranielnjyhqn
      mranielnjyhqn

      zhdwiksdgyaf viagra 100 mg dose candian pharmacy viagra information can you buy cialis without a prescription in canada
      viagra forum

    4. xganieletpvnk
      xganieletpvnk

      xdaccpbazhry cialis canadian viagra prescription viagra 100mg price canadian pharmacies prescription required cialis
      viagra online cheap

    5. omanielfkizrl
      omanielfkizrl

      ttiskremjysr online viagra sales is generic viagra safe online prescription viagra pharmacy in canada to buy cialis
      free viagra sample pack

    6. dganielyrtbat
      dganielyrtbat

      cwftkksjldll female viagra drug buying cialis from canada pharmacy viagra overnight cialis canadian phamacy
      buy generic viagra online

  17. floongeweizem
    floongeweizem

    sildenafil first time dose cialis price does sildenafil cause shortness of breath

    1. loanielkfjbvd
      loanielkfjbvd

      moponvcagejq cheap viagra cialis pharmacy prices tadalafil generic best prices health first rx pharmacyfor cialis capsules
      buy viagra online canada

    2. nzanielipcbfv
      nzanielipcbfv

      cvxnqeezjbhz canada pharmacy cialis viagra online shop online generic viagra canadian pharmacy non prescription cialis
      buying cialis canada

  18. floongeweizem
    floongeweizem

    role of viagra in ivf http://viagraivo.com best dose of cialis

    1. MarvinhiB
      MarvinhiB

      http://www.cezar71.ru/communication/forum/user/3419/
      http://www.t-inweb.ru/forum/user/14200/
      http://culart.gov39.ru/forum/user/2312/
      http://ribkadomoy.ru/communication/forum/user/1460/
      http://xn--f1apaaqe.xn--p1ai/forum.php/?PAGE_NAME=profile_view&UID=14615
      http://www.dtpochevidets.ru/forum/user/608885/
      http://archivcat.com/communication/forum/user/13896/
      http://b-buh.ru/communication/forum/user/2006/
      http://kupit-shp.ru/forum/user/9864/
      http://portraitist-murashkina.ru/communication/forum/user/1115/
      http://tutdelo.ru/forum/user/2995/
      https://partsukraine.com/forum/?PAGE_NAME=profile_view&UID=7070
      http://gromada.ru/forum/?PAGE_NAME=profile_view&UID=4781
      https://www.kalpa-vriksa.ru/forum/index.php?PAGE_NAME=profile_view&UID=25723
      http://ng58.ru/forum/user/26463/

    2. MarvinhiB
      MarvinhiB

      http://pay.enjoymoscow.com/forum/index.php?PAGE_NAME=profile_view&UID=23048
      http://www.dveri-ural.ru/communication/forum/index.php?PAGE_NAME=profile_view&UID=30414
      http://www.ag-club.ru/forum/?PAGE_NAME=profile_view&UID=3871
      https://1dentist.ru/forum/user/1076/
      http://infotechstroi.ru/communication/forum/user/5178/
      http://siamsi.ru/communication/forum/user/7168/
      http://autoden.com.ua/forum/?PAGE_NAME=profile_view&UID=920
      http://kupit-shp.ru/forum/user/9864/
      http://takebest.ru/forum/?PAGE_NAME=profile_view&UID=74829
      http://ribkadomoy.ru/communication/forum/user/1460/
      http://intellect-audit.ru/forum/?PAGE_NAME=profile_view&UID=2984
      http://saltikovka.com/forum/user/79898/
      https://modul-company.com/forum/user/1041/
      http://adm-tbilisskaya.ru/city/forum/?PAGE_NAME=profile_view&UID=8602
      http://harmonyl.ru/forum/user/1274/

  19. floongeweizem
    floongeweizem

    how to buy sildenafil on craigslist http://www.cialisoni.com/ buy cialis, what is in a viagra shot

  20. floongeweizem
    floongeweizem

    health risks taking viagra http://viaqraonlinegen.com http://viaqraonlinegen.com/, sildenafil for kidney stones

    1. BolshakovErnst1993Rok
      BolshakovErnst1993Rok

      4166 men viagra for sale

      http://viagraiqox.com/ - viagra sales valentines day
      viagra online

      click now buy generic viagra

    2. BolshakovErnst1993Rok
      BolshakovErnst1993Rok

      is prescription amount

      3c7e is pfizer internet

      1. jpxwyp
        jpxwyp

        e2gsovb payday loans az
        http://loandayfastgo.com/ - payday loans shreveport
        payday loans fresno
        online payday loans no credit check no teletrack payday loans

      2. ujanielaqnetk
        ujanielaqnetk

        tpduokrmxueb viagra effects on women how viagra works cheapest price viagra cialis-canada
        cheap viagra generic

    3. BolshakovErnst1993Rok
      BolshakovErnst1993Rok

      iss a bajo coste

      3c7e chantillon de is rapide

    4. GavrilovMaron1990Rok
      GavrilovMaron1990Rok

      is no at

      54dd is ato mxico

    5. 용인출장안마
      용인출장안마

      It's really very complex in this active life to listen news on TV, therefore I only use the web
      for that reason, and obtain the most recent news.

      1. qxcae
        qxcae

        mljfanl payday loans payday loans

      2. iraniellqqahe
        iraniellqqahe

        lelmkyptxtnt cialis canada buy generic viagra tadalafil canadian thu?c cialist canada
        alternative to viagra

      3. cdanielthtttu
        cdanielthtttu

        mrocyodvukfv viagra drug viagra erection when will viagra go generic cialis candian pharmacy
        viagra jelly

    6. 바카라사이트
      바카라사이트

      Very great post. I just stumbled upon your weblog and wanted to
      mention that I have truly enjoyed surfing around your
      blog posts. In any case I will be subscribing in your feed and I am hoping you write once more very soon!

    7. Insert Your Data
      Insert Your Data

      insert your data

    8. http://motors-assured.com/__media__/js/netsoltrademark.php?D=brandvel.ru%2fbitrix%2frk.php%3Fgoto%3dhttps%3a%2f%2fdeoropweepu1977.hexat.com%2f
    9. Business Directory
      Business Directory

      Helpful information. Lucky me I found your web site by chance, and I am surprised why this twist of fate did not happened in advance!
      I bookmarked it.

    10. Dohogworlge1983.Xsl.Pt
      Dohogworlge1983.Xsl.Pt

      The broa spectrujm of dances includes contemporary, classical,
      ballroom, street, jazz, hip-hop, musical theatre and every
      one of their sub-genres. You caan visit visit to gett yourself a DVD Creator to create
      your photos right into a DVD. In most cases tis iis not a challenge as users can order prints from the sharing
      site.

    11. affordable luxury fashion
      affordable luxury fashion

      Oh my goodness! Awesome article dude! Thank
      you so much, However I am having difficulties with your
      RSS. I don't understand the reason why I can't subscribe to
      it. Is there anybody having identical RSS issues? Anybody who knows thee solution wjll you kindly respond?
      Thanx!!

    12. child porn escorts
      child porn escorts

      This website certainly has all of the information I wanted concerning this subject and didn't know who
      to ask.

    13. Organizational Culture
      Organizational Culture

      I all the time used to read paragraph in news papers but now as
      I am a user of net thus from now I am using net for articles,
      thanks to web.

    14. 4th grade writing prompts
      4th grade writing prompts

      The broad spectrum of dances includes contemporary, classical, ballroom, street, jazz, hip-hop,
      musical theatre and all of their sub-genres. As the first part
      oof the Lyrics break, there is no doubt she is tattling about a ppast kinship (.
      Hilary Duff also became a singer from being simply a star of her own Disney
      Channel show, Lizzie Maguire.

    15. wgRuime
      wgRuime

      http://genericcilaken.com/ - canada pharmacy online cheapest viagra prices buy generic cialis

    16. grsAtopy
      grsAtopy

      http://buyjeacialonline.com/ - buy cialis cheap discount generic viagra canadian pharmacy meds

    17. geghuppy
      geghuppy

      http://onlinevigra.com/ - best canadian pharmacy viagra online pharmacy when does viagra go generic

    18. fbgenhah
      fbgenhah

      http://onlinesslviaqra.com/ - canada pharmacy online cheapest viagra prices online canadian pharmacy

    19. rghDraws
      rghDraws

      http://cheapnowaaaa.com/ - viagra generic viagra soft pills canadian pharmacy meds

    20. rbsplani
      rbsplani

      http://onlinewwwmen.com/ - online pet pharmacy viagra generic canada drugs coupon code

    21. hrfPoego
      hrfPoego

      http://viagrageneric7k.com/ - my canadian pharmacy prescription viagra buy cialis online reddit

    22. nniRuime
      nniRuime

      http://mobilleaderapply.com/ - quick advance financial fast unsecured cash loan

    23. fsaPoego
      fsaPoego

      http://myleaderusa.com/ - alabama payday loans 1 hour payday loans pay day now

    24. hashuppy
      hashuppy

      http://jslpaydayloans.com/ - cash advance idaho canadian online payday loan lend money

    25. 카지노사이트
      카지노사이트

      We are a group of volunteers and opening a brand new scheme in our community.
      Your web site offered us with helpful info to work on. You've performed an impressive
      process and our whole neighborhood will be thankful to you.

    26. lmanielfywvef
      lmanielfywvef

      ghlahblomvgo payday loans shreveport a payday loan payday loans with no bank account required payday loans nashville tn

    27. etplani
      etplani

      http://buyvlaqra.com - cvs pharmacy online viagra price buy cialis online overnight shipping

      1. AaronGaf
        AaronGaf

        cipro amoxil

    28. FrghjDraws
      FrghjDraws

      http://canadaonlinepharmacyhtik.com/ - canadian online pharmacy cialis viagra tablets for sale canadian online pharmacy reviews

    29. dbfhDeala