我有两个班级:Main - Activity
和Second - AsyncTask
。我想mymethod
在按钮点击时触发。
我试过了。
public class Second extends AsyncTask<Void, Void, Void> {
Main main;
@Override
protected void onProgressUpdate(Void... values) {
// TODO Auto-generated method stub
super.onProgressUpdate(values);
main = new Main(); //Wrong because is an Activity
Button con = (Button)activity.findViewById(R.id.con);
con.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
main.mymethod(v);
}
});
}
}
但它抛出java.lang.IllegalStateException: System services not available to Activities before onCreate()
。