我试图实施:
Executor executor = new Executor() {
@Override
public void execute(@NonNull Runnable command) {
}
};
ProviderInfoRetriever.OnProviderInfoReceivedCallback callback = new ProviderInfoRetriever.OnProviderInfoReceivedCallback() {
@Override
public void onProviderInfoReceived(int i, @Nullable ComplicationProviderInfo complicationProviderInfo) {
Log.d("MyWatchFace", complicationProviderInfo.providerName);
}
};
ProviderInfoRetriever providerInfoRetriever = new ProviderInfoRetriever(MyWatchFaceService.this, executor);
providerInfoRetriever.init();
providerInfoRetriever.retrieveProviderInfo(callback,
new ComponentName(
getApplicationContext(),
MyWatchFaceService.class)
, COMPLICATION_IDS);
可悲的是,我在调试日志中看不到任何内容:/
我在executor
或其他什么地方做错了吗?
答案 0 :(得分:1)
似乎我不得不使用特定的执行者:
Executor executor = Executors.newSingleThreadExecutor();
ProviderInfoRetriever.OnProviderInfoReceivedCallback callback = new ProviderInfoRetriever.OnProviderInfoReceivedCallback() {
@Override
public void onProviderInfoReceived(int i, @Nullable ComplicationProviderInfo complicationProviderInfo) {
Log.d("MyWatchFace", complicationProviderInfo.providerName);
}
};
ProviderInfoRetriever providerInfoRetriever = new ProviderInfoRetriever(getApplicationContext(), executor);
providerInfoRetriever.init();
providerInfoRetriever.retrieveProviderInfo(callback,
new ComponentName(
getApplicationContext(),
MyWatchFaceService.class)
, COMPLICATION_IDS);
答案 1 :(得分:1)
是的,您的Executor
做错了。这是我的一个看起来像(并且它正在工作):
final Executor executor = new Executor() {
@Override
public void execute(@NonNull Runnable r) {
new Thread(r).start();
}
};
让我觉得你错过了Thread
代码。