Android: Passing variables to an already running s

2020-07-02 10:15发布

I am having issues passing a value from an Activity to an already running service. I was wondering what the best approach to take would be? Adding extras wont work as I believe this has to be done before the intent is started? (correct me if i'm wrong).

Any help would be great! I can elaborate if needed.

Dan.

1条回答
Root(大扎)
2楼-- · 2020-07-02 11:02

If your service is not an IntentService, you can call startService(...) as many times you want. The service will run the first time but next calls will result in new onStartCommand() calls with the new extras you need.

Check this answer and the doc.

查看更多
登录 后发表回答