I have some service that need to start repeatedly by user input or given default value, so i need to add parameter to handle it,
I have tried this:
@ReactMethod
public void start(){
start(1000);
}
@ReactMethod
public void start(int timer){
Intent i = new Intent(reactContext, ServiceUploadData.class);
i.putExtra("Interval", timer);
reactContext.startService(i);
}
but those code show an error
start got 0 arguments, expected 1
anyone can help me?
Although I haven’t seen it in the docs I have seen this in the code
We do not support method overloading since js sees a function as an object regardless of number of params.
To get around this issue you could do one of the following.
public void start()
, perhaps to public void startWithDefault()
public void start(int timer)
and handle the initial value on the JavaScript sideif
to check an initial value has been set and then call the appropriate function. The second and third option allow you to keep your api the same to the user as they will only ever be interacting with the JavaScript.