我希望单击按钮即可在App.js
类中使用此Promise值。请帮助我找出解决方案。
@ReactMethod
public void initTimerService(Promise promise)
{
TimerService timerService = App42API.buildTimerService();
String timerName = "<Enter_your_timer_name>";
long timeInSeconds= 120;
timerService.createOrUpdateTimer(timerName, timeInSeconds, new App42CallBack() {
public void onSuccess(Object r)
{
Log.e(TAG,"response = " + r);
Timer timer = (Timer)response;
promise.resolve(timer.getName());
System.out.println("Timer Name is: " + timer.getName());
System.out.println("Time is: " + timer.getTimeInSeconds());
}
});
}
答案 0 :(得分:0)
public void initTimerService(Callback callback)
{
TimerService timerService = App42API.buildTimerService();
String timerName = "<Enter_your_timer_name>";
long timeInSeconds= 120;
timerService.createOrUpdateTimer(timerName, timeInSeconds, new
App42CallBack() {
public void onSuccess(Object r)
{
Log.e(TAG,"response = "+r);
Timer timer = (Timer)response;
promise.resolve(timer.getName());
System.out.println("Timer Name is: "+timer.getName());
System.out.println("Time is: "+timer.getTimeInSeconds());
callback.invoke(true);
}
});
}