Hi,
I had an activity which calls a thread for 10times one after another. However, if the network is slow or too much information loaded, force close will occur. Will adding sleep in each thread help to solve this problem? or is there any other ways to solve it?
public void run() {
if(thread_op.equalsIgnoreCase("xml")){
readXML();
}
else if(thread_op.equalsIgnoreCase("getImg")){
getWallpaperThumb();
}
handler.sendEmptyMessage(0);
}
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
int count = 0;
if (!myExampleHandler.filenames.isEmpty()){
count = myExampleHandler.filenames.size();
}
count = 5;
if(thread_op.equalsIgnoreCase("xml")){
pd.dismiss();
thread_op = "getImg";
btn_more.setBackgroundResource(R.drawable.btn_more);
}
else if(thread_op.equalsIgnoreCase("getImg")){
setWallpaperThumb();
index++;
if (index < count){
Thread thread = new Thread(GalleryWallpapers.this);
thread.start();
}
}
}
};