点击暂停无法在下载时获得响应

时间:2012-09-04 03:06:12

标签: android

当我下载时,点击暂停,但没有回应。 我不知道具体如何描述,实际上它意味着停止,但实在无法实现。 代码

public void onClick(View v) {

                      [color=#FF0000]if (flag == 0){//click mark[/color]

无法显示,红色只是一个标记。 代码如下

holder.btns .setOnClickListener(new OnClickListener(){
                @Override
                public void onClick(View v) {

                  [color=#FF0000]if (flag == 0){//judge the click mark[/color] 

                    holder.ratingBarScore.setVisibility(View.GONE);
                    holder.pro.setVisibility(View.VISIBLE);
                    holder.textView.setVisibility(View.VISIBLE);
                    if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
                    }else {
//                        Toast.makeText(this, "there is no SD card", 1000).show();
                        Log.v("wjp", "7889900");
                    }
                    final String downloadUrl =(String)v.getTag();
                    Thread thread = new Thread(){
                        int count = 0;
                        public void run(){
                          Log.v("ccf", "onClick");
                          try {
                              downLoadFile(context, downloadUrl, gameName, holder);    
                              openFile(context, new File("/sdcard/9twan/"+ gameName +".apk"));
                              if(!WebHelper.REGISTER_FLAG){
                                  Log.v("GamesInfoListAdapter", "WebHelper.REGISTER_FLAG == false");
                                  String imei, mac, mobile_number, model, brand;
                                  boolean flag;
                                  TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
                                  imei = tm.getDeviceId();
                                  if(imei == null){
                                      imei = "CUSTOM" + WebHelper.generateRandomIMEIString(15);
                                  }
                                  mac = null;
//                                  mac = tm.getDeviceId(); 
                                  if(mac == null){
                                      mac = "CUSTOM" + WebHelper.generateRandomMacString(17);
                                  }
                                  mobile_number = tm.getLine1Number();
                                  model = tm.getLine1Number();
                                  brand = tm.getLine1Number();
                                  flag = WebHelper.regDevice(context, "install", imei, mac, mobile_number, model, brand);
                                  if(flag){
                                      WebHelper.REGISTER_FLAG = true;
                                      Log.v("GamesInfoListAdapter", "WebHelper.REGISTER_FLAG == true");
                                  }
                              }

                          }catch (Exception e){
                              e.printStackTrace();
                          }
                        }
                    };
                    Log.v("wjp", "running"+thread.getName());
                    thread.start();
                    Toast.makeText(context, "begin to download" + gameName, 0).show();
                    holder.btns.setBackgroundResource(R.drawable.tab_out);

                    [color=#FF0000]flag =1;[/color]//here is need to pause,how to write?
                    }else {
                          if(Thread.currentThread() !=null){
                              Thread.interrupted();
//                              Thread = null;
                          }
//                        thread.
//                        Thread.interrupted();//pause return boolean
//                        Thread.sleep(3000);
//                          Thread.

                        holder.btns.setBackgroundResource(R.drawable.tab_install);
                        flag =0;

                    }
                }

            });
        }
        return convertView;

1 个答案:

答案 0 :(得分:0)

您正在尝试中断当前线程,您应该中断已启动的线程。你也改变了旗帜的价值。您似乎有多个名为flag

的变量
if(thread !=null){
 thread.interrupt();      
}