I need to give a delay of 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 happens that all of this gets inside a handler and it gives me the following error:
java.lang.RuntimeException: Can not create handler inside thread that has not called Looper.prepare ()
I read about it, it would have to run on the main thread, but I can not do it.