简体   繁体   English

Android活动识别和位置客户端

[英]Android activity recognition and location client

I want to use an ActivityRecognitionClient and a LocationClient in the same Activity. 我想在同一活动中使用ActivityRecognitionClient和LocationClient。 The trouble is that either calls onConnected. 麻烦的是要么调用onConnected。

I would like to use both eg to write the location and the recognized activity to a database. 我想同时使用例如将位置和已识别的活动写入数据库。

I thought that should be a rather easy thing to do but could not find out how. 我认为这应该是一件很容易的事,但找不到答案。 Hope someone can help. 希望有人能帮忙。

UPDATE 更新

I use Services now instead of Activities and implement the clients separately, connecting when the service is started and disconnecting when it is destroyed. 我现在使用服务而不是活动,并分别实现客户端,在启动服务时进行连接,在销毁服务时断开连接。

The same activity cannot implement two methods with the same name from different interfaces. 相同的活动不能从不同的接口实现两个具有相同名称的方法。 This is well explained here Java - Method name collision in interface implementation Java-接口实现中的方法名冲突在这里得到了很好的解释

You might want to make separate classes implementing each interface separately and call your methods to read/write to your database from both of them. 您可能需要制作单独的类,分别实现每个接口,然后调用您的方法以从这两个方法读取/写入数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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