关于线程的重用

关天重复调用线程的问题:

class thread extends Thread{

		@Override
		public void run() {
			//取数据
			try {
				city=getIntent().getStringExtra("CityName");
				if(city==null){
					city="珠海";
				}else{
					int index=city.indexOf("(");
					city=city.substring(0, index-1);
				}
				//SoapObject来存储返回的数据
				detail=gws.getWeather(city);
			} 
			catch (Exception e) {
				e.printStackTrace();
			}finally{
				Message msg = new Message();
				msg.what = 1;
				mHandler.sendMessage(msg);
			}
		}
		
	}


启动线程.只需要
thread  th;
th=new thread();
th.start();

而当需要再调用回这个纯种方法时,也是只需要
                th=new thread();
th.start();

这样是不会产生线程has started 的异常的..因为在Handler里再start线程时..前一个线程已经被QT回收了..这样就可以new 这个线程方法.启动了!!!


评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值