我做了这个活动,但任务没有开始。我对其进行了调试,onStart() 进入 task.execute() 行,但它从未进入 doInBackground()。在正在运行的任务列表中有一个 AsyncTask,我假设它是这个。我只是看不出问题出在哪里。这是代码。
package pl.edu.elka.pw.hosewski.wifi;
public class NetDetail extends Activity implements OnClickListener{
private LineGraph lgNet;
private WifiManager wifi;
private WiFiDetail net;
private DBSource dbs;
private DBWifi dbw;
private TextView ssid;
private TextView bssid;
private TextView freq;
private TextView capab;
private SharedPreferences getPrefs;
private int interval;
private LineRefresh task;
private ViewSwitcher psSwitch;
private Button bSwitch;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.netdetail);
dbs = new DBSource(this);
dbs.open();
getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
wifi = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
psSwitch = (ViewSwitcher) findViewById(R.id.psSwitch);
bSwitch = (Button) findViewById(R.id.bSwitch);
lgNet = (LineGraph) findViewById(R.id.lgNet);
lgNet.setClickable(true);
lgNet.setOnClickListener(this);
bSwitch.setOnClickListener(this);
Bundle b = getIntent().getExtras();
long i = b.getLong("index");
dbw = dbs.getWifi(i);
net = WiFiList.getDetailByBSSID(dbw.getBssid());
lgNet.setDetail(net);
ssid = (TextView) findViewById(R.id.tvSSID);
bssid = (TextView) findViewById(R.id.tvBSSID);
freq = (TextView) findViewById(R.id.tvFrequen);
capab = (TextView) findViewById(R.id.tvCapab);
ssid.setText(dbw.getSsid());
bssid.setText(dbw.getBssid());
freq.setText(dbw.getFrequency() + " MHz");
capab.setText(dbw.getCapability());
this.setTitle(dbw.getSsid()+ " - detale");
interval = Integer.parseInt(getPrefs.getString("intervals", "5"));
task = new LineRefresh();
}
class LineRefresh extends AsyncTask<Void, Void, Void>{
@Override
protected void onProgressUpdate(Void... values) {
// TODO Auto-generated method stub
super.onProgressUpdate(values);
updLines();
}
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
while(wifi.isWifiEnabled()){
publishProgress();
try {
Thread.sleep(interval);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(isCancelled()){
break;
}
}
return null;
}
}
public void updLines(){
lgNet.setDetail(net);
lgNet.postInvalidate();
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
dbs.close();
task.cancel(true);
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
task.execute();
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.lgNet:
psSwitch.showNext();
break;
case R.id.bSwitch:
psSwitch.showPrevious();
break;
}
}
}