iPhone explains UIWebwiew as "You use the UIWebview class to embed web content in your application. …..".
Android explains it as "A View that displays web pages. This class is the basis upon which you can roll your own web browser or simply display some online content within your Activity.…..".
Well is it limited to displaying web pages ?
Developing network based applications has always been challenging for developers. Well what makes it so challenging? For a desktop application we can assume that the resources will be available on demand. But when dealing with a network based application there is no guarantee as to whether we will receive the requested resource or even if it exists. Therefore the application must capable of recovering from such exceptions.
The two key factors affecting performance are latency and bandwidth. In desktop applications it doesn't matter much if you are accessing resources serially, but when it comes to network based applications, things change. Latency is more or less the same for every request. If you are accessing multiple resources serially, latency adds up and the delay increases. So as developers it is our job to reduce the effect of latency, which points us to parallel access of resources.
For this we could modify the system such that, the downloading of data is performed in the background, hidden from the end user. In such a situation, the user interactions are still possible, thereby masking the actual delay.
There are different ways of implementing this. But we need to adopt the method which presents us with less inconsistency, less code and less worry.
Consider a system, which requires loading images in sets of ten at a time. Here, the view will be filled with hundred or more images arranged in a grid, more like Mozilla’s Add On ‘Cooliris, but without that cool 3D effect. Now, you integrate an audio player which performs online streaming. The obvious solution for this will be using a separate class.
Let’s see how these can be implemented with lesser amount of coding without reducing the performance or consistency.
Taking the case of image loading, create a UIWebView, in the place of an UIImageView. Append HTML script to a string, which would load the image, load the webview and handles everything else for us. Here HTML script would be script tags with an img tag having source specified to that images url.
Once these initializations are done a webview would be displayed and its content is fetched on access. To have more control over the webview, implement the functions declared in its delegate protocol UIWebViewDelegate. This allows us to handle events such as loading webview, loading finished, link clicked etc.
The size of the webview can be changed easily in accordance with the image size by just finding the image size using javascript and adjusting the webview accordingly.
Coming to the audio player, there is no need for creating a class which handles streaming, playing, pausing etc. Webview can implement the same functionality in a much easier way. Initialize the webview with the URL of the file to be played and you’re done! A separate class can be substituted with just a few lines of code.
Some android tablets had an issue in supporting the Android Google API. By creating a local webpage which loaded a map using Google Maps Javascript API V3, this problem can be solved. It is also possible to create a javascript interface in an activity which helped in accessing resources from the local webpage during execution.
Definitely webview is for displaying webpages and its contents, but utilizing it in right places at the right time gives us much more than that.
iPhone/Android Development Team
Related posts:
Tags: android application, android google, android tablet, iphone, webview
