简体   繁体   中英

How to call my background service's public method from listview adapter

In my activity inside onStart() I bind into my custom service and create an instance of the service then I can call my service's public methods. Inside onStop() then I do unbindservice(myservice).

How can I do the same inside my listview adapter that extends BaseAdapter?

(There are public methods and variables I need to access inside onClickListener of my list items.)

If you succeed binding service with the activity then its simple to implement.

Just pass the service instance to the adapter either in constructor or via method. Then use the service instance on the adapter's OnClick mehtod.

MyService s;
...
// Binding is done s is service instance then
MyAdapter adapter = new MyAdapter(activityInstance, s, your data)

You might have access to the service instance s inside the adapter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM