![]() ![]() ![]() Static final String ACTION_PAUSE = "com.floatingwidgetchathead_demo.SampleService. ![]() Here, we are going to see an example to call one activity from another and. We can also pass the information from one activity to another using explicit intent. In other words, we can call another activity in android by explicit intent. Static final String ACTION_PLAY = "com.floatingwidgetchathead_PLAY" Android Explicit intent specifies the component to be invoked from activity. Then your Service be like this : static final String ACTION_START = "com.floatingwidgetchathead_START" ![]() When the service is started its onStartCommand() method will be called so in this method you can retrieve the value (UserID) from the intent object for example public int onStartCommand (Intent intent, int flags, int startId) The program is successfully compiled and run on a Windows system. ServiceIntent.putExtra("UserID", "123456") Here is source code of the Program to Start a Service to Start and Stop a Service in Android. So from an activity you will create the intent object to start service and then you place your data inside the intent object for example you want to pass a UserID from Activity to Service: Intent serviceIntent = new Intent(()) When you create a Service you should override the onStartCommand() method so if you closely look at the signature below, this is where you receive the intent object which is passed to it: public int onStartCommand(Intent intent, int flags, int startId) For a precise answer to this question on "How to send data via intent from an Activity to Service", Is that you have to override the onStartCommand() method which is where you receive the intent object: ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |