In part 1 of this Battle of the SDKs post I wrote about how both Android and iPhone SDKs have a solid implementation of the MVC paradigm. Now it's time to dive in a little deeper and see how both platforms make sharing data between applications possible, providing many more ways for your application to rock its way into the mobile world.
Sharing Data and communication between applications is a big part of any operating system. Up until the launch of OS 3.0 iPhone SDK didn't provide many means for applications to communicate between one another or simple methods for sharing data. However, with the arrival of iPhone's OS 3.0 sharing data is now a possibility.
The first option for sharing data between applications is the new pasteboard (UIPasteboard) which can access system copy & paste data, can hold different data types and more than one item per type. Applications can easily put data in the pasteboard expecting others to retrieve it.
NSData pbdata = [pasteboard dataForPasteboardType:KUTTypeVCard];
NSData *vCardData = [self generateVCardForPerson:thePerson]
[pasteboard setData:vCardData forPasteBoardType:KUTTypeVCard];
The example above shows how one app can put a person's data in the pasteboard for another to read. This mechanism alone, however is not really ideal. How will an application know someone just placed data in the pasteboard for it to read? This is why iPhone OS 3.0 has also introduced new launch methods which allow an application to better understand how it was invoked and with what options.
1)- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
this method replaces the common �didFinishLaunching� and provides a dictionary with options on how an application was launched.
: Key available to your application, that contains the URL an application was called with.
: Key available to your application, that contains information about which application sent the URL.
: Key available to your application, that tells you whether a user tapped on the iphone push notification services dialog to open your application.
With these mechanisms, iPhone SDK has taken an important step into making collaboration between applications a reality.
Android OS, is all about applications and services working together to bring the best user experience possible to Android users. It is no surprise then that it relies on the most important concept of Android programming to make it possible, the Intent.
An intent is, in very simple words, something your app wants to do. This means �I want to search something� or �I want to open a browser�, etc. If the intent describes something that wants to be done, then there needs to be something that takes care of an Intent. This something is the IntentFilter. An IntentFilter in Android, declares the capability of assisting an Intent.
By creating Intents, and with applications providing IntentFilters, Android has created a whole world of collaboration between applications.
An application declares an intent filter inside its main configuration file AndroidManifest.xml in the following way.
<activity android:name="PictureViewer" android:label="@string/app_name">
<category android:name="android.intent.category.DEFAULT" />
<action android:name="com.test.pictures.VIEW_LIST" />
In the code above, the intent filter defines a category and an action. Categories and action for IntentFilters are very simple to understand. Both are plain string objects that specify what kind of Intents and IntenFilter can handle. The action declared in the IntentFilter MUST match the one an Intent was called with, however if an IntentFilter does not specify an action, it will match any action coming from any Intent. For categories, the IntentFilter can specify more categories than the one declared by the Intent but it MUST have at least the category the Intent specified. Below is an example of an Intent that will match the IntentFilter declaration above and start the PictureViewer Activity.
Intent intent = new Intent(�com.test.pictures.VIEW_LIST�);
Android also allows you to send data to other Activities in the form of a URI. The code below shows how you can create an Intent with data.
Intent theIntent = new Intent(Intent.ACTION_PICK,Uri.parse("content://contacts/
Both Android and iPhone provide different means for communicating between applications and you can use both to your advantage when developing your new app. Keep in mind that unlike iPhone, Android allows applications to run in the background. Because of this, not all Android applications are graphical. They can be services executing a certain task or listening to broadcasts from other applications. Imagine how the options become almost limitless when you can interact with services, broadcast receivers and graphical applications. So if you are thinking of building something from scratch that your application will need for either OS, better see if there's some other app out there you can collaborate with, or better yet, why don't you build something a whole bunch of apps will be interested in using?!