Simon Williams
- Forum posts: 5
Aug 3, 2011, 4:29:25 PM via Website
Aug 3, 2011 4:29:25 PM via Website
Hi,
I have an AsyncTask that is doing some processing but when it is finished I cannot get it to fire the HandleEvent method af a Handler object (I hope that terminology is correct).
Here is my code:
public class main extends Activity {
/** Called when the activity is first created. */
public Handler mHandler;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// code here to start the background task - all working fine
mHandler = new Handler() {
public void HandleMessage(Message msg) {
Log.v("Handler", "in HandleMessage");
}
};
}
}
final class SendItemToServer extends AsyncTask<Void, Void, Integer> {
@Override
protected Integer doInBackground (Void ... arg0) {
// some code here to connect to my server - all this is working, data is saved on the server
mHandler.sendEmptyMessage(0);
return 0;
}
@Override
protected void onPostExecute(Integer result) {
super.onPostExecute(result);
}
}
The error is on the line mHandler.sendEmptyMessage(0); in the AsyncTask - the error is "mHandler cannot be resolved".
Thanks for any help.
Simon
I have an AsyncTask that is doing some processing but when it is finished I cannot get it to fire the HandleEvent method af a Handler object (I hope that terminology is correct).
Here is my code:
public class main extends Activity {
/** Called when the activity is first created. */
public Handler mHandler;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// code here to start the background task - all working fine
mHandler = new Handler() {
public void HandleMessage(Message msg) {
Log.v("Handler", "in HandleMessage");
}
};
}
}
final class SendItemToServer extends AsyncTask<Void, Void, Integer> {
@Override
protected Integer doInBackground (Void ... arg0) {
// some code here to connect to my server - all this is working, data is saved on the server
mHandler.sendEmptyMessage(0);
return 0;
}
@Override
protected void onPostExecute(Integer result) {
super.onPostExecute(result);
}
}
The error is on the line mHandler.sendEmptyMessage(0); in the AsyncTask - the error is "mHandler cannot be resolved".
Thanks for any help.
Simon
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.