maandag 21 december 2009

Am I Fragment or am I Bundle

Sometimes you want to know if there are fragments attached to a bundle so you can perform some logic. Eclipse's Platform class is able to help you in this area because it lets you get a list of BundleDescription objects like this:

BundleDescription[] binfos = Platform.getPlatformAdmin().getState(false).getBundles();
for (BundleDescription bundleDescription : binfos) {
if(bundleDescription.getHost() != null)
System.out.println("I am Fragment");