I'm probably looking at a solution which isn't going to work, but the idea was to start a new activity from the bundle (which also contains that activity) in the bundle.start method like so:
Intent i = new Intent(); i.setAction(Intent.ACTION_MAIN); i.addCategory(Intent.CATEGORY_LAUNCHER); ComponentName cn = new ComponentName(this.getBaseContext(), DrawActivity.class); i.setComponent(cn); startActivity(i); The activity has an onCreate method which creates an instance of DrawView which contains an onDraw method which draws something on the screen using a canvas. (tested and working without implementing it in an OSGi bundle) This results in the following: 04-03 13:32:45.074: D/Felix(15691): Felix state: 32 04-03 13:32:45.584: I/System.out(15691): DEBUG: WIRE: [5.0] package; (package=android.app) -> [0] 04-03 13:32:45.584: I/System.out(15691): DEBUG: WIRE: [5.0] package; (package=android.content) -> [0] 04-03 13:32:45.584: I/System.out(15691): DEBUG: WIRE: [5.0] package; (package=android.graphics) -> [0] 04-03 13:32:45.584: I/System.out(15691): DEBUG: WIRE: [5.0] package; (package=android.media) -> [0] 04-03 13:32:45.584: I/System.out(15691): DEBUG: WIRE: [5.0] package; (package=android.os) -> [0] 04-03 13:32:45.594: I/System.out(15691): DEBUG: WIRE: [5.0] package; (package=android.util) -> [0] 04-03 13:32:45.594: I/System.out(15691): DEBUG: WIRE: [5.0] package; (package=android.view) -> [0] 04-03 13:32:45.594: I/System.out(15691): DEBUG: WIRE: [5.0] package; (package=android.widget) -> [0] 04-03 13:32:45.594: I/System.out(15691): DEBUG: WIRE: [5.0] package; (package=org.osgi.framework) -> [0] 04-03 13:32:45.594: I/System.out(15691): DEBUG: WIRE: [5.0] package; (package=org.osgi.util.tracker) -> [0] 04-03 13:32:45.614: D/dalvikvm(15691): DexOpt: --- BEGIN 'bundle.jar' (bootstrap=0) --- 04-03 13:32:45.784: D/dalvikvm(15691): DexOpt: --- END 'bundle.jar' (success) --- 04-03 13:32:45.784: D/dalvikvm(15691): DEX prep '/data/data/com.osgi.integration/files/felix/cache/bundle5/version0.0/bundle.jar': unzip in 2ms, rewrite 170ms 04-03 13:32:45.825: W/System.err(15691): org.osgi.framework.BundleException: Activator start error in bundle bnd.drawbundle [5]. 04-03 13:32:45.834: W/System.err(15691): at org.apache.felix.framework.Felix.activateBundle(Felix.java:1864) 04-03 13:32:45.834: W/System.err(15691): at org.apache.felix.framework.Felix.startBundle(Felix.java:1734) 04-03 13:32:45.844: W/System.err(15691): at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:905) 04-03 13:32:45.844: W/System.err(15691): at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:892) 04-03 13:32:45.844: W/System.err(15691): at com.osgi.integration.AndroidOSGiActivity.installTestBundle(AndroidOSGiActivity.java:59) 04-03 13:32:45.844: W/System.err(15691): at com.osgi.integration.AndroidOSGiActivity.access$0(AndroidOSGiActivity.java:45) 04-03 13:32:45.844: W/System.err(15691): at com.osgi.integration.AndroidOSGiActivity$1.onClick(AndroidOSGiActivity.java:140) 04-03 13:32:45.844: W/System.err(15691): at android.view.View.performClick(View.java:2485) 04-03 13:32:45.844: W/System.err(15691): at android.view.View$PerformClick.run(View.java:9080) 04-03 13:32:45.844: W/System.err(15691): at android.os.Handler.handleCallback(Handler.java:587) 04-03 13:32:45.844: W/System.err(15691): at android.os.Handler.dispatchMessage(Handler.java:92) 04-03 13:32:45.844: W/System.err(15691): at android.os.Looper.loop(Looper.java:123) 04-03 13:32:45.844: W/System.err(15691): at android.app.ActivityThread.main(ActivityThread.java:3683) 04-03 13:32:45.854: W/System.err(15691): at java.lang.reflect.Method.invokeNative(Native Method) 04-03 13:32:45.854: W/System.err(15691): at java.lang.reflect.Method.invoke(Method.java:507) 04-03 13:32:45.854: W/System.err(15691): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 04-03 13:32:45.854: W/System.err(15691): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 04-03 13:32:45.854: W/System.err(15691): at dalvik.system.NativeStart.main(Native Method) 04-03 13:32:45.854: W/System.err(15691): Caused by: java.lang.NullPointerException 04-03 13:32:45.864: W/System.err(15691): at android.content.ComponentName.<init>(ComponentName.java:75) 04-03 13:32:45.864: W/System.err(15691): at com.osgi.integration.drawbundle.Activator.start(Activator.java:47) 04-03 13:32:45.864: W/System.err(15691): at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:633) 04-03 13:32:45.864: W/System.err(15691): at org.apache.felix.framework.Felix.activateBundle(Felix.java:1817) 04-03 13:32:45.864: W/System.err(15691): ... 17 more I can't imagine this having anything to do with the Android life cycle, the main application remains on the foreground all the time for the time being during this early stage of development. DDMS also doesn't show anything related to this. Although I do understand what you mean with Android closing things it renders unnecessary. I'm pretty sure it has to be something with the context passed to the component name, or the declaration of the intent properties which doesn't seem to work in OSGi context and does work in a normal Android application. When I instantiate a new DrawActivity and don't use it, it doesn't show any errors, it might be a wrong conclusion, but I assume the problem must be in starting the activity then. (I tested this to make sure it wasn't a dependency or other bundle/OSGi related problem) Maurice On Tue, Apr 3, 2012 at 1:28 PM, Angelo van der Sijpt < [email protected]> wrote: > Yay, another BNDtools convert! :) > > I'm not sure what you mean by "get a Nullpointer when trying to draw > something on the screen"; perhaps you're missing an Acitivity or something. > Remember that, at least in my experience, the Android lifecycle prevails, > and OSGi has to be fit into that. > > Angelo > > > On Apr 3, 2012, at 11:23 AM, M. van Ree wrote: > > > Hey Angelo, > > > > For the moment I've only just used BNDTools to generate the manifest > which > > seems to work well now, the class mismatch error is gone now. > > However, I do get a Nullpointer when trying to draw something on the > screen > > using the imported packages. But I guess that occurs because the bundle > > probably can't use the application context just like that by passing it > > along. > > > > Thanks for your answers, certainly helped me fix a rather annoying thing, > > wish I had used BNDTools earlier on... > > > > Maurice > > > > > > On Mon, Apr 2, 2012 at 12:04 PM, Angelo van der Sijpt < > > [email protected]> wrote: > > > >> Hi Maurice, > >> > >> See inline. > >> > >> On Apr 2, 2012, at 11:51 AM, M. van Ree wrote: > >> > >>> I was considering the use of BNDTools indeed, and will look into that > for > >>> sure now. > >>> I didn't know about the Bundle-ManifestVersion, will look into that > too! > >>> The comma is indeed a copy-paste error, as you can see in the bottom > >> import > >>> statement, I closed the last one without a comma. But, sharp to notice! > >> > >> Well, it's important to have a good view of what actually is going on in > >> your code (it could be a simple typo). > >> > >>> > >>> As far as tools go, I'm just using Eclipse Indigo and the latest > Android > >>> SDK, dexing and packaging jars with the tools (dx and aapt) from the > SDK. > >>> When opening the bundle jarfile, the API isn't in there, I don't know > >> what > >>> happens after installing and starting the bundle on Felix though...I > can > >>> actually install a bundle and print something to the console or use > Log.d > >>> to show a message in Logcat, so the bundle (without using Android > >>> libraries) does seem to be packaged in the right way I guess? > >> > >> You can use dexdump to inspect the (dalvik-)contents of a bundle. > >> > >>> > >>> I'll report back here how things work out after trying BNDTools. > >> > >> Good luck! > >> > >>> > >>> Maurice > >> > >> Angelo > >> > >>> > >>> On Mon, Apr 2, 2012 at 11:18 AM, Angelo van der Sijpt < > >>> [email protected]> wrote: > >>> > >>>> Right. > >>>> > >>>> I'm not entirely sure what's up, but some things come to mind, > >>>> - in stead of building the manifest by hand, you should consider using > >>>> something like BND (perhaps with BNDTools, if you're an Eclipse user) > to > >>>> handle that for you. If you don't need to use DynamicImport, stick > with > >>>> 'regular' imports: that way, the framework can inform you better about > >>>> what's wrong. > >>>> - your bundle should have a "Bundle-ManifestVersion: 2" to state that > it > >>>> is an R4 bundle (again, BND will do that for you). > >>>> - your Import-Package statement seems to have a comma after > >>>> org.osgi.framework . I'm not sure whether that is a copy-paste error, > or > >>>> whether it is actually relevant. (<insert-bnd-notice/>) > >>>> - what tools do you use for building your project? Is it possible that > >> the > >>>> Android API ends up _inside_ your bundle? > >>>> > >>>> Angelo > >>>> > >>>> On Apr 2, 2012, at 10:59 AM, M. van Ree wrote: > >>>> > >>>>> Hello Angelo, > >>>>> > >>>>> Thank you for your fast response! > >>>>> Here is some more info: > >>>>> > >>>>> a: > >>>>> public FelixManager(String rootPath) > >>>>> { > >>>>> this.rootPath = rootPath; > >>>>> felixProperties = new FelixProperties(this.rootPath); > >>>>> > >>>>> bundlesDir = new File(rootPath+"/felix/bundle"); > >>>>> if (!bundlesDir.exists()) { > >>>>> if (!bundlesDir.mkdirs()) { > >>>>> throw new IllegalStateException("Unable to create bundles > dir"); > >>>>> } > >>>>> } > >>>>> cacheDir = new File(rootPath+"/felix/cache"); > >>>>> if (!cacheDir.exists()) { > >>>>> if (!cacheDir.mkdirs()) { > >>>>> throw new IllegalStateException("Unable to create felixcache > >>>> dir"); > >>>>> } > >>>>> } > >>>>> > >>>>> try > >>>>> { > >>>>> felix = new Felix(felixProperties); > >>>>> felix.start(); > >>>>> } > >>>>> catch (Exception ex) > >>>>> { > >>>>> ex.printStackTrace(); > >>>>> } > >>>>> } > >>>>> > >>>>> The felix properties are defined as following: > >>>>> > >>>>> private String m_felixAbsolutePath; > >>>>> public FelixProperties(String rootpath) > >>>>> { > >>>>> m_felixAbsolutePath = rootpath; > >>>>> put("org.osgi.framework.storage", > m_felixAbsolutePath+"/felix/cache"); > >>>>> put("felix.cache.rootdir",m_felixAbsolutePath+"/felix"); > >>>>> put("felix.log.level", "4"); > >>>>> put("felix.startlevel.bundle", "1"); > >>>>> put("org.osgi.framework.system.packages.extra", > >>>>> ANDROID_PACKAGES_FOR_EXPORT); > >>>>> } > >>>>> private final String ANDROID_PACKAGES_FOR_EXPORT= > >>>>> "android; " + > >>>>> "android.app;" + > >>>>> "android.content;" + > >>>>> "android.database;" + etc. etc. > >>>>> > >>>>> and b: > >>>>> > >>>>> Manifest-Version: 1.0 > >>>>> Bundle-Name: drawbundle > >>>>> Bundle-Activator: com.osgi.integration.drawbundle.Activator > >>>>> Bundle-SymbolicName: com.osgi.integration.drawbundle > >>>>> Bundle-Version: 0.0.1 > >>>>> Import-Package: org.osgi.framework, > >>>>> DynamicImport-Package: android.* > >>>>> > >>>>> I first, to no avail, tried including the Android packages manually > in > >>>> the > >>>>> Import-Package statement, like so: > >>>>> > >>>>> Import-Package: org.osgi.framework, > >>>>> android.view.LayoutInflater, > >>>>> android.view.View, > >>>>> android.widget.LinearLayout, > >>>>> android.app.Activity, > >>>>> android.app.TextView > >>>>> > >>>>> I've also tried including the Android jarfile in another bundle, and > >>>>> exporting the packages from there, and then importing that bundle in > >> the > >>>>> above manifest. > >>>>> > >>>>> Maurice > >>>>> > >>>>> On Mon, Apr 2, 2012 at 10:39 AM, Angelo van der Sijpt < > >>>>> [email protected]> wrote: > >>>>> > >>>>>> This could have something to do with the way you instantiate your > >>>>>> framework, _or_ with the way your bundle is packaged. > >>>>>> Could you post (a) your framework instantiation code, and (b) the > >>>> manifest > >>>>>> of your bundle? > >>>>>> > >>>>>> Angelo > >>>>>> > >>>>>> > >>>>>> On Apr 2, 2012, at 10:18 AM, M. van Ree wrote: > >>>>>> > >>>>>>> Hello all, > >>>>>>> > >>>>>>> I have a problem when trying to make the Android lib available to > my > >>>> OSGi > >>>>>>> bundles. > >>>>>>> The error I'm getting is: > >>>>>>> > >>>>>>> 04-02 08:03:00.351: W/dalvikvm(18531): Method mismatch: onDraw in > >>>>>>> Lcom/osgi/integration/drawbundle/DrawView; (cl=0x4067bb40) and > super > >>>>>>> Landroid/view/View; (cl=0x0) > >>>>>>> 04-02 08:03:00.391: W/System.err(18531): Caused by: > >>>>>> java.lang.LinkageError: > >>>>>>> Classes resolve differently in superclass > >>>>>>> > >>>>>>> Off course I can see the cl=0x0, so that must be the culprit, but I > >>>> have > >>>>>> no > >>>>>>> idea on how to get it fixed... > >>>>>>> I'm exporting the packages as following in a properties class: > >>>>>>> > >>>>>>> private static final String ANDROID_PACKAGES_FOR_EXPORT = > >>>>>>> ("android; " + > >>>>>>> "android.app;" + > >>>>>>> "android.content;" + > >>>>>>> "android.database;" + > >>>>>>> etc. etc. ); > >>>>>>> > >>>>>>> I'm really drawing a blank here on what could be wrong, I would > >> expect > >>>> to > >>>>>>> receive an error on exporting/importing something empty that would > >>>> point > >>>>>> me > >>>>>>> in the right direction, but it doesn't seem to be the case. > >>>>>>> Who can tell me what I'm doing wrong here? > >>>>>>> > >>>>>>> > >>>>>>> Regards, > >>>>>>> Maurice > >>>>>> > >>>>>> > >>>>>> > >>>>>> > --------------------------------------------------------------------- > >>>>>> To unsubscribe, e-mail: [email protected] > >>>>>> For additional commands, e-mail: [email protected] > >>>>>> > >>>>>> > >>>>> > >>>>> > >>>> --------------------------------------------------------------------- > >>>> To unsubscribe, e-mail: [email protected] > >>>> For additional commands, e-mail: [email protected] > >>>> > >>>> > >> > >> > >> > >> --------------------------------------------------------------------- > >> To unsubscribe, e-mail: [email protected] > >> For additional commands, e-mail: [email protected] > >> > >> > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > >

