Ho due attività nella mia applicazione. Nella mia attività A sto usando un AsyncTask e la seconda attività B anche usando un altro AsyncTask. Nella mia attività A ho caricato alcuni dati sul server e nella mia attività B sto cercando di scaricare altri dati dal server. Entrambi questi sono in esecuzione in AsyncTask. Il mio problema è quando ho provato a scaricare i dati dal server nel metodo Attività B onPreExecute()
ma il metodo doInBackground()
non è stato chiamato è in attesa della prima attività di Attività A doInBackground()
terminata. Perché è successo? E 'possibile eseguire più di un fondo azioni in un momento stesso ..È possibile eseguire più AsyncTask nello stesso tempo?
In Activity Un
ImageButton submit_button = (ImageButton) findViewById(R.id.submit_button);
submit_button.setOnClickListener(new OnClickListener()
{
public void onClick(View record_button)
{
new Save_data().execute();
}
});
class Save_data extends AsyncTask<String, Integer, Integer>
{
protected void onPreExecute()
{
}
protected Integer doInBackground(String... arg0)
{
//uploading data here
}
}
nella mia attività di B
ImageButton get_button = (ImageButton) findViewById(R.id.get_button);
get_button.setOnClickListener(new OnClickListener()
{
public void onClick(View record_button)
{
new download_process().execute();
}
});
class download_process extends AsyncTask<String, integer, integer>
{
protected void onPreExecute()
{
Log.e("pre-execute","has been called");//This Log works well
}
protected Integer doInBackground(String... arg0)
{
//downloading data here
}
}
come utilizzare esecutore .. per favore mi dica .. – Amsheer
possibile duplicato - (http://stackoverflow.com/questions/ [l'esecuzione di più AsyncTasks allo stesso tempo non è possibile?] 406 8984/running-multiple-asynctasks-at-the-time-not-possible) - che fornisce un'ottima spiegazione –