Start / Stop Fragment Programmatically

◇◆丶佛笑我妖孽 提交于 2019-12-25 03:43:11

问题


I want to implement a feature toggle in OSGI, which means I want to start and stop bundles programmatically.

For plug-ins that's really easy:

Bundle plugin = //...
plugin.start();
plugin.stop();

For fragments it's not so easy. Stopping does not work at all, and if I use uninstall() the fragment is gone for good, and I'm not able to install it again, since I don't know the correct location for BundleContext#installBundle(...) (and looking at Bundle#getLocation(), neither does the fragment itself).

The problem I'm facing is I have a fragment contributing to some Eclipse extension points. Just stopping the host plug-in will not remove these services (for whatever reason). So I need to stop the fragment manually (or maybe clear that stupid Eclipse cache that keeps screwing applications up?).

So how can I install fragments at runtime?


回答1:


Fragments do not have their own life cycle. They are part of the life cycle of their host bundle. That means there is no way to start/stop them independently of the host.

If you need more background about bundles, fragments and life cycles, I advise you to read the OSGi specification, which can be downloaded from the http://osgi.org/ website.



来源:https://stackoverflow.com/questions/29773056/start-stop-fragment-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!