Android:将变量传递到已运行的服务 [英] Android: Passing variables to an already running service

查看:83
本文介绍了Android:将变量传递到已运行的服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将值从活动"传递到已经运行的服务时遇到问题.我想知道最好的方法是什么?添加额外功能不会起作用,因为我认为这必须在意图启动之前完成? (如我错了请纠正我).

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.

丹.

推荐答案

如果您的服务不是IntentService,则可以多次调用startService(...).该服务将首次运行,但下一次通话将导致新的onStartCommand()通话以及您需要的新功能.

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.

检查此答案 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆