Android 隐藏 Activity 异步调用
我是 android 新手,正在构建一个 Android 库,其中有一个奇怪的用例,如下所示:
Method(parms...){
if(somedata exists in local filestore)
make webservice call and set result;
else
start activity with webview and get result from activity
}
}
如果第一个条件成功,我希望它异步调用 Web 服务,而第二个条件则调用一个活动,我将调用该活动think 需要位于同一线程上,以允许调用者获取活动结果。
我正在考虑使用像发现的那样的隐藏活动 此处。但对我来说这似乎很老套。还有其他建议吗?我认为在库中拥有两个单独的方法可能会更干净,但如果可能的话我想将它们放在一起。
I am new to android and I am building an Android library where I have a weird use case like the following:
Method(parms...){
if(somedata exists in local filestore)
make webservice call and set result;
else
start activity with webview and get result from activity
}
}
If the first condition succeeds I would like it to make the webservice call asynchronously, while with the second, an activity is invoked which I think needs to be on the same thread to allow the caller to get the activity result.
I was thinking to use a hidden activity like the one found here. But it seems very hacky to me. Any other suggestions? I am thinking it might just be cleaner to have two separate methods in the library but I would like to keep them together if possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有 UI 的 Activity,您是指 Service 吗?请阅读本文档。它描述了如何对此服务进行同步和异步调用。
An Activity without UI, do you mean a Service? Please read this document. It describes how to do synchronous and async calls to this service.