I have an implementation of AsyncTask in my application, but I have a problem.
Here is my implementation of AsyncTask:
public class AsyncTaskPost extends AsyncTask<URL, Void, Void> {
private View mView;
private ProgressBar mProgressbar;
private Context mContext;
public AsyncTaskPost(View view, Context context){
mView = view;
mProgressbar = (ProgressBar)mView.findViewById(R.id.progressPostUser);
mContext = context;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressbar.setVisibility(View.VISIBLE);
}
@Override
protected Void doInBackground(URL... urls) {
try{
Thread.sleep(5000);
return null;
}
catch (Exception ex) {
return null;
}
}
@Override
protected void onPostExecute(Void aVoid) {
Toast.makeText(mContext, "Finished", Toast.LENGTH_SHORT);
}
@Override
protected void onProgressUpdate(Void... values) {
mProgressbar.setVisibility(View.VISIBLE);
}
@Override
protected void onCancelled() {
super.onCancelled();
}
}
Here is how I call it:
public void onSaveClicked(User user) {
try {
String nameTest = user.get_name();
String surnameTest = user.get_surname();
new AsyncTaskPost(mView, mContext).execute(new URL("www.blahblah.com"));
//new AsyncTaskPost(mView, mContext).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new URL("www.blahblah.com"));
}
catch (Exception ex) {
}
}
When I debug the app, I can step into the constructor, but after that, none of the onPreStart
, 'doInBackground' is called?
Why is this happening?