Your Question: How Pass Data from Activity to Services in Android?
Contents

How pass data from activity to service in Android?

Android provides a way to pass values between activity and sub-activities and services and each others, using the getExtras(). putExtra method, which takes the key name (string) and its value. This passed value can be recovered when the intent is handled (being it service or activity).

How pass data from activity to already running service?

Sending Intents to the Service

When the Service is already running and the Activity invokes startService() with a new Intent object, then Android will pass this new Intent to the onStartCommand(). In an Intent object we can pass data or control command to the Service.

Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article
Twitter Facebook Pinterest