Class MyActivity extends Activity{
CommunicationWithDBCls communic=new CommunicationWithDBCls();
call(){
imgAsynTask = new ImageShowAsyncTask(this, imgUrlAryLi, count,
this, progress);
imgAsynTask.execute();
}
}
And
public ImageShowAsyncTask(
ArrayList<String> arryLisUrl, int count, Context cont,
ProgressBar progress) {
// some stuff
}
@Override
protected Bitmap doInBackground(Void… paramArrayOfParams) {
try{
//some stuff related to getting image from server n saving it to DB
}catch(Exception e){
}finally{
communic.close();
}
}
}
inside the asyncTask, I just passed the reference of my database class while calling the constructor of asyncTask from
the activity.
the correct Code is like this:
CommunicationWithDBCls communic=new CommunicationWithDBCls();
imgAsynTask = new ImageShowAsyncTask(this, imgUrlAryLi, count,
this, progress,communic);
imgAsynTask.execute();
}
}
And
public class ImageShowAsyncTask extends AsyncTask<Void, String, Bitmap> {
CommunicationWithDBCls communic;
public ImageShowAsyncTask(
ArrayList<String> arryLisUrl, int count, Context cont,
ProgressBar progress, CommunicationWithDBCls communic2) {
//some stuff
}
@Override
protected Bitmap doInBackground(Void… paramArrayOfParams) {
try{
//some stuff related to getting image from server n saving it to DB
}catch(Exception e){
}
}
}
Comments are closed.