有什么办法可以绑定动态壁纸服务吗?
我有一个动态壁纸,它在我的自定义 WallpaperService 类中加载和设置了一些资源。像这样的事情:
class MyLiveWallpaperService extends WallpaperService {
MyResources sharedResources;
public onCreate() {
// set up some resources
}
public MyResources getSharedResources() {
return sharedResources;
}
}
我还有一个针对此动态壁纸的首选项活动,该活动已在 res/xml/wallpaper.xml 中正确设置。我想要的是以某种方式为这个 PreferencesActivity 提供对这些共享资源的访问权限。我知道我可以将它们设置为公共静态字段,但我更喜欢更干净的解决方案 - 如果有一种方法可以绑定到壁纸服务(这样我就可以访问 MyLiveWallpaperService 实例),那就太酷了。
最后,在我的情况下,活动和服务处于同一进程中,因此描述为 在开发指南中访问本地服务应该可以,但是WallpaperService文档不鼓励覆盖 onBind()方法使这个想法不可能实现。
还有其他办法吗? :)
I have a live wallpaper which has some resources loaded and set up inside my custom WallpaperService class. Something like this:
class MyLiveWallpaperService extends WallpaperService {
MyResources sharedResources;
public onCreate() {
// set up some resources
}
public MyResources getSharedResources() {
return sharedResources;
}
}
And I also have a preferences activity for this live wallpaper that is properly set in res/xml/wallpaper.xml. What I want is to somehow provide this PreferencesActivity an access to these shared resources. I know I could make them public static fields but I prefer a cleaner solution - if only there was a way to bind to wallpaper service (so I could access a MyLiveWallpaperService instance) that would be rly cool.
In the end activity and service are in the same process in my case, so something described as accessing local service in dev guide should work, BUT WallpaperService docs discourage overriding onBind() method which makes this idea impossible to come true.
Is there any other way? :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也想绑定到动态壁纸服务,但不可能。如果您想将数据传递到壁纸服务,也许您可以使用 SharedPreferences 作为使用静态字段的替代方法
i also wanted to bind to a live wallpaper service but is not possible. If you want to pass data to a wallpaper service maybe you can use SharedPreferences as a alternative to use static field