Can a package be handed over to a service?

In my application, I need to get the value from activity to service. The value I need to get is the one I clicked in this operation.

For example, if I select the element x [i] from Activity A, I need to get the value x [i] in service S.

How is this possible?

Thanks,

Nicky

+6
android android-intent android-service
source share
3 answers

In the service, use this:

public int onStartCommand (Intent intent, int flags, int startId) { super.onStartCommand(intent, flags, startId); Bundle bundle = intent.getExtras(); } 
+7
source share

When you create an intent, you can put data in it, and the same data will be transmitted along with the intent when the service starts.

 Intent intent = new Intent(context, Class) ; intent.putExtra(key, value); startService(intent); 

At the end of the reception, get the intention and get additional value from it.

 Bundle b = getIntent().getExtra(); b.get<ValueType>(key); 
+2
source share

You can override the onStartCommand(Intent intent, int flags, int startId) in the service.

0
source share

All Articles