Android - 从服务启动Activity
可能的重复:
如何从服务启动 Activity?
我有服务,它检查应用程序版本,如果有新版本,它应该提示我功能齐全的安装意图。我的问题是 - 如何从服务开始关注实际屏幕?
编辑:我想到了 int status,我将比较实际安装的版本和网络上的版本。如果有更新的版本,我将设置status=1。对于我的应用程序中的每个意图,我添加 if 子句:
If(status==1){
// prompt installation intent
}
但是如何获取在服务类中声明和初始化的这个“状态”?
谢谢
Possible Duplicate:
How to start an Activity from a Service?
I have service, which checks app versions and if there is new, it should prompt my fully functioning installation intent. My question is - how to start intent on actual screen from service?
Edit: I have thought of int status, i will compare actual version installed and version on the web. If there is newer version, I will set status=1. And for each intent in my app i add if clause:
If(status==1){
// prompt installation intent
}
but how to get this "status" which is declared and inicialized in service class?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你问两个问题。
似乎可以从服务启动活动。
android 从服务启动 Activity
但是,我强烈建议您使用警报机制来通知用户更新已准备就绪,而不是通过完全更改上下文来“撤回”。
关于您的“状态”变量,您可以考虑将其存储在 SharedPreferences 中,该变量可以在服务和活动中访问。
http://developer.android.com/reference/android/content /SharedPreferences.html
You ask two questions.
It seems possible to launch an Activity from a service.
android start activity from service
However I would strongly recommend you used the Alert mechanism to inform the user an update was ready, rather than 'pulling the rug' with a complete change of context.
Regarding your 'status' variable, you may consider storing this in SharedPreferences which will be accessible in both the service and the activities.
http://developer.android.com/reference/android/content/SharedPreferences.html