Android 空闲时运行应用程序
我想知道是否有一种方法可以在手机空闲/锁定时继续运行我的应用程序(基本上每 X 秒刷新一次 URL)? (当屏幕关闭时)。我目前正在使用 WebView 来加载 URL,并使用 Runnable 来重新加载它。
当我尝试使用服务时,它不断给我带来问题 - webview 无法解决。我查了一下,没能解决。
我也想知道有没有办法在后台浏览URL。基本上,在不显示浏览器的情况下浏览 URL :D
任何帮助将不胜感激! 抱歉,如果这些问题很愚蠢,我才开始 Android 编程几天。
I was wondering if there is a way to keep running my application (which basically just refreshes a URL every X seconds) even when the phone idles/locks? (when the screen turns off). I'm currently using a WebView to load the URL, and a Runnable to reload it.
When I tried using a service, it keeps giving me a problem - webview cannot be resolved. I looked it up, and I couldn't get it fixed.
I would also like to know if there is a way to browse a URL in the background. Basically, browsing a URL without showing the browser :D
Any help would be much appreciated!!!
Sorry if these questions are dumb, I've only started Android programming for a few days.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你不需要 webview 来访问 web 服务器,除非你想立即显示结果。
您可以使用内置的 http 客户端来实现此目的(通过服务工作,不使用用户界面)
You do not need a webview to poke web server, unless you like to display results imeediately.
You can use built in http client for this purpose ( works from service and does not vae user interfce)
我认为
Timer
任务将解决您的问题。I think
Timer
task will solve your problem.