Note that there are some explanatory texts on larger screens.

plurals
  1. POAsyncTask is restarting when i press back button
    primarykey
    data
    text
    <p>I have an activity with multiple AsyncTask's, but when i press back button, the Activity is reloaded and the AsyncTask's are executed again. what should i do to Back to the previous activity and not reload the activity and asynctask ? please help.</p> <pre><code>public class LugarActivity extends SherlockActivity { CargarDatos cargarDatos; CargarComentarios cargarComentarios; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_lugar); cargarDatos = new CargarDatos(); cargarCometarios = new CargarComentarios(); loadData(); } public void loadData(){ cargarDatos.execute(); } public void loadOtherData(){ cargarComentarios.execute(); } public class CargarDatos extends AsyncTask&lt;Integer, Integer, String&gt;{ @Override protected String doInBackground(Integer... params) { // here download data } @Override protected void onPostExecute(String html) { loadOtherData(); } } public class CargarComentarios extends AsyncTask&lt;Integer, Integer, String&gt;{ @Override protected String doInBackground(Integer... params) { // here download data } } } </code></pre> <p><strong>FIXED!</strong></p> <p>i fixed the problem with Singleton class:</p> <pre class="lang-java prettyprint-override"><code>public class DataManager { private static DataManager instance = null; protected static boolean isShowingTheView = false; protected DataManager() { } public static synchronized DataManager getInstance() { if (instance == null) { instance = new DataManager(); } return instance; } } </code></pre> <p>in the activity i add this code:</p> <pre class="lang-java prettyprint-override"><code>DataManager dataManager = new DataManager(); if(!dataManager.isShowingTheView){ loadData(); dataManager.isShowingTheView = true; }else{ finish(); } </code></pre> <p>and finally i override the onDestroy() method</p> <pre class="lang-java prettyprint-override"><code>@Override public void onDestroy(){ dataManager.isShowingTheView = false; super.onDestroy(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload