3
I need to delay 5 seconds in one of the parts of my application:
final Runnable runnable = new Runnable() {
@Override
public void run() {
// Encadeia trabalho serializado
jobChain.append(new Job() {
public void doJob(final OnChainItemListener itemListener) {
// Obtém metadados do Artigo
onlineArticle.get(idArticle, new HttpJsonObjectListener() {
public void onRequestCompleted(JSONObject object, Integer httpStatus, CharSequence msg) {
offlineArticle.save(object, new HttpJsonObjectListener() {
public void onRequestCompleted(JSONObject object, Integer httpStatus, CharSequence msg) {
Log.v(this.getClass().getName(), "Artigo salvo!");
}
}, null);
itemListener.onRequestCompleted(object, httpStatus, msg);
}
}, defFail);
}
});
}
};
new Handler().postDelayed(runnable, 5000);
I tried to implement, but it turns out that all this gets inside an Handler and it gives me the following error:
java.lang.Runtimeexception: Can’t create Handler Inside thread that has not called Looper.prepare()
I read about it, that I would have to run on the main thread, but I’m not getting it done.
Can you post your main thread code? That’s where the other thread was called, the main thread.
– Giancarlo Abel Giulian
I believe you are calling methods that deal with interface within a thread that is not allowed to do so. Take a look at this response here from the O.R. link
– Dener