There are three possible states of request when we enter an activity.
From the documentation, I understand if we use execute() in onStart(), it takes care of cases 1,3 but not case 2(when request is in process). We need to use addListenerIfpending() for that
Workaround I used is use addListenerIfPending() in onStart(), and use execute in onRequestNotFound()
protected void onStart(){
super.onStart();
getSpiceManager().addListenerIfPending(my.class,"mykey",new myRequestListener());
}
public final class myRequestListener implements PendingRequestListener<result> {
@Override
public void onRequestFailure(SpiceException spiceException){
}
@Override
public void onRequestSuccess(final RoundInfo roundInfo) {
}
@Override
public void onRequestNotFound(){
getSpiceManager().execute(request,"mykey", DurationInMillis.ONE_DAY,new myRequestListener());
}
}
I want to know if this is the correct way, the way it's meant to be done.
Also, please comment if there will be any performance issues
No, your first statement is wrong.
execute()
will take in charge all 3 cases.
addListenerIfPending
will not trigger any request by itself, it only allows to plug a listener to an already pending request if such a request exists. So case 2.