The connection between activity and service

I have an Activity with EditText and some checkboxes. After the user inserts the text, the text must be sent to the Service, and the Service will run in the background, showing Toast from time to time.

It is very difficult for me to find how to send data (strings and logical values ​​that the user enters through Activity) to the service .

0
source share
2 answers

Use Intent on Activity put values ​​in puExtra

Intent intent = new Intent(current.this, YourClass.class);
intent.putextra("keyName","value"); 

and then call StartService to call the OnStart method .. in the service, get the values ​​in OnStart using the intent

Bundle extras = getIntent().getExtras();
   if (extras != null) 
   {
     String value = extras.getString("key");
   }
+1

Android?

, , :)

(: OnStartCommand())

google " android" , :

Activity to Service

0

All Articles