我正在显示一些加载对话框。由于不同的网络呼叫,它们有点闪存,所以有时我的空闲资源会报告它现在是空闲但实际上加载对话框刚刚被一个网络呼叫解除,但随后又被另一个网络呼叫触发。让我们来看看我的资源:
public class LoadingDialogIdlingResource implements IdlingResource {
private final FragmentManager manager;
private final String tag;
private ResourceCallback resourceCallback;
public LoadingDialogIdlingResource(FragmentManager manager, String tag) {
this.manager = manager;
this.tag = tag;
}
@Override
public String getName() {
return LoadingDialogIdlingResource.class.getName() + ":" + tag;
}
@Override
public boolean isIdleNow() {
//this is being called to quickly, i want to slow it down without suspending the entire thread
manager.executePendingTransactions();
boolean idle = (manager.findFragmentByTag(tag) == null);
Timber.d("check if idle:" + idle);
if (idle) {
resourceCallback.onTransitionToIdle();
}
return idle;
}
@Override
public void registerIdleTransitionCallback(ResourceCallback resourceCallback) {
this.resourceCallback = resourceCallback;
}
}
这是我到目前为止所尝试的内容:
IdlingPolicies.setIdlingResourceTimeout(45000L,TimeUnit.MICROSECONDS);
但这不是我想要的,这是系统的超时。我只是想减慢系统检查其idleNow一秒钟的频率。所以要清楚,我正在寻找一种方法来减慢检查isIdleNow()方法。