带有WallpaperService子类的IPC
我正在尝试在 Android 上制作动态壁纸。我有一个类
public class MyWallpaperService extends WallpaperService {
}
和另一个类:
public class SettingsActivity extends Activity {
}
我需要使 SettingsActivity 与 MyWallpaperService 通信,以便在动态壁纸上设置值。我之前使用过aidl,并尝试将其应用于这种情况。然而,WallpaperService 似乎具有以下方法:
/**
* Implement to return the implementation of the internal accessibility
* service interface. Subclasses should not override.
*/
@Override
public final IBinder onBind(Intent intent) {
return new IWallpaperServiceWrapper(this);
}
因此,由于超类(WallpaperService)的 onBind 方法的最终声明,我无法在服务的 onBind 方法中返回我自己的自定义 aidl 定义的绑定器。在我看来,这似乎是 Android 平台开发团队的疏忽。这是否有效地消除了任何动态壁纸中所有可能的进程间通信能力?
我在这里有什么选择?我知道我可以将活动和服务放在同一个进程中,并让活动在服务上设置全局变量,但这似乎会很快变得混乱,我想正确执行此操作。在服务中添加广播接收器是正确的做法吗?
I am trying to make a live wallpaper on Android. I have one class
public class MyWallpaperService extends WallpaperService {
}
And annother class:
public class SettingsActivity extends Activity {
}
I need to make the SettingsActivity communicate with MyWallpaperService in order to set values on the live wallpaper. I have used aidl before and have tried to apply it to this situation. However it seems like WallpaperService has the following method:
/**
* Implement to return the implementation of the internal accessibility
* service interface. Subclasses should not override.
*/
@Override
public final IBinder onBind(Intent intent) {
return new IWallpaperServiceWrapper(this);
}
Therefore I cannot return my own custom aidl defined binder in the onBind method of my service due to the final declaration on the superclass, WallpaperService's, onBind method. To me this seems like an oversight by the Android platform development team. Does this effectively removes all possible inter process communication abilities from any live wallpaper?
What are my options here? I know I can put the Activity and the Service in the same process and have the Activity set global variables on the Service, but that seems like it could get messy fast and I want to do this right. Is adding a Broadcast Receiver in the Service the right move here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您还可以使用广播来实现壁纸服务和某些控制器活动之间的通信,来源如下。
http://developer.samsung.com/android /technical-docs/服务与活动之间的有效通信
You could also use BroadCasts to achieve communication between a wallpaper service and some controller activity, source below.
http://developer.samsung.com/android/technical-docs/Effective-communication-between-Service-and-Activity