//global
private AsyncTask<String,String,String> myAsync;
//inside my activity
public class Myreceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
String arg[] = {intent.getStringExtra("id")};
myAsync= new AsyncTask<String, String, String>(); //error here
myAsync.execute(arg);
}
}
错误是:
无法实例化AsyncTask类型
为什么?
答案 0 :(得分:1)
它是一个示例AsyncTask Activity ..
public class StockWatch extends Activity {
String myData;
Button refresh;
myHtmlParser myParser;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
refresh = (Button)findViewById(R.id.refresh);
myParser = new myHtmlParser();
refresh.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
myAsyncTask myWebFetch = new myAsyncTask();
myWebFetch.execute();
}
});
}
class myAsyncTask extends AsyncTask<Void, Void, Void> {
TextView tv;
myAsyncTask() {
//default constructor
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
//do your stuff
}
@Override
protected void onPreExecute() {
super.onPreExecute();
//do your stuff
}
@Override
protected Void doInBackground(Void... arg0) {
//do your stuff
}
}
}
有关详细信息,请参阅here