Showing posts with label broadcast. Show all posts
Showing posts with label broadcast. Show all posts

2010/06/26

Inter-process Communication of BlackBerry

Maybe I just don’t know how to read the docs, or how to Google, but I was looking for this info way too much, somehow it was burried. In any case – let’s say you have to apps on the device, and they use a common PersistenStore. One app adds stuff there in the background. The other – shows a UI with a list of the items from the store. All nice and synchronized. The only problem is – there is no way to detect that the PersistentObject that you are using was updated! So if you want to have your list refreshed automatically – you have to get creative.

On the producer side, after updating the PersistentStore, post a global notification with a unique ID:
ApplicationManager.getApplicationManager().postGlobalEvent(Main.NOTIFICATIONS_ID_1);

On the consumer side (UI), register for the notifications, then catch that message and update the UI accordingly:

2010/06/20

Shaking on the iPhone

Let’s say you have an iPhone application with many different View Controllers, and in some of them you want to detect a ‘Device Shake’ event. You can’t just catch it in the Controller itself, since it provide methods for that. So the solution is this – you subclass a UIWindow to detect an event and then broadcast it to your app. Then catch the event in appropriate places using NSNotificationCenter.

Don’t forget to change the parent class of your main Window to MotionWindow to catch the events.

Enjoy, here's the code: