D
D
Denis Afonin2015-09-30 19:46:10
Android
Denis Afonin, 2015-09-30 19:46:10

How to pass multiple parameters to a service?

There is a main activity from which the service is launched via onBindService (). I found lessons in which they pass one parameter at a time. And how to make it possible to pass several variables to the service at once?
The first thing I tried was calling the procedure inside the service from the activity with passing parameters:

kvService.changeservice(KVStartTime_btn.getText().toString(), KVNorma_btn.getText().toString());

Procedure inside the service:
public void changeservice(String kvStartTime, String kvNorma){
...
}

But on startup, it throws a java.lang.NullPointerException .
PS: Now I thought, can I transfer data to the service as well as from it, via Broadcast?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Berkov, 2015-10-01
@konstantin_berkow

Read the article about Bound Services , you can organize a messenger and send messages to the service through its binder, you can communicate with broadcasts, then the binder is not needed. You can make your own binder, you can do it in different ways.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question