Example code of mutual communication between service and activity in Android

preface

In Android, activity is mainly responsible for the display of foreground pages, and service is mainly responsible for tasks that need to be run for a long time. Therefore, in our actual development, we often encounter the communication between activity and service. This paper introduces in detail the relevant contents about the communication between service and activity in Android, and shares them for your reference and learning, I won't say much now. Let's take a look at the detailed introduction.

Activity communicates with service

The first method: call the service method through mybinder

MainActivity

BanZhengService

The second method: call the service method through the interface iservice

MainActivity

DemoService

Interface iservice

summary

The above is the whole content of this article. I hope the content of this article has a certain reference value for your study or work. If you have any questions, you can leave a message. Thank you for your support for programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>