参考图片。我正在尝试构建一个 POC,其中在搜索时用户当前位置包含在搜索结果中(不是所有用户,而是只有在搜索中返回的用户。所有这些用户都已经登录到我的应用程序中,我已经知道他们的用户 ID . 我尝试运行一个服务,以便我可以在后台获取用户位置并使用以下技术将其广播到我的搜索片段,除了我使用服务方法而不是 IntentService:
public class MyIntentService extends IntentService {
//ACTION should include application package convention, just to show that this can
//be any string
public static final String ACTION = "mycustomactionstring";
public MyIntentService() {
super("MyIntentService");
// TODO Auto-generated constructor stub
Log.d("sohail", "service started");
}
@
Override
protected void onHandleIntent(Intent arg0) {
// TODO Auto-generated method stub
Log.d("sohail", "onHandleIntent called");
Intent in = new Intent(ACTION); //you can put anything in it with putExtra
Log.d("sohail", "sending broadcast");
LocalBroadcastManager.getInstance(this).sendBroadcast( in );
}
}
问题是我如何在 Android 中反映仅在搜索结果中提供特定用户的当前位置?Android 中是否有更好的方法允许我们为所有登录用户中的特定用户执行类似 user.getLastLocation 的操作?这里有什么好的方法吗?
我基本上在寻找的是一种在 Android 中轻松说出“给我在搜索结果中返回的特定用户的当前位置”的方式这些用户是所有登录用户的一部分
我想跟踪所有用户的位置并将其保存在数据库中并将其与搜索结果中返回的用户进行比较,但这似乎不是理想的方式?
在这种情况下有人可以提出更好的建议吗?任何帮助将不胜感激。