I have a nested fragment containing the following method:
public void onSave() { if (getActivity() == null || view == null) return; if (file != null && file.exists()) { new AsyncTask<Void, Void, Void>() { @Override protected void onPreExecute() { Log.d("log", "onPreExecute of save ex"); } @Override protected Void doInBackground(Void... params) { Log.d("log", "doInBackground of save ex");
My problem is that if I call this method for the first time, it will execute until onPostExecute (). However, if I move to another fragment and reopen this fragment (by creating a new fragment object and replacing it), then only onPreExecute () is executed. Why is this asyncTask not executing a second time?
Intentionally, if I use executeOnExecutor (), then it works fine a second time. But why does the execute () function not work? Is AsyncTask's life related to a fragment or something else?
Thanks in advance!
source share