Thinking Aloud
DropBox SDK and Android

So recently i worked on Dropbox SDK provided by the Dropbox team and tried to integrate it with an android app. Wouldn’t say it was easy but i got through it, and they the result is worth the time spent. :). I am writing this for anybody who wants to use dropbox api and i bothered by the wide spread info.

So here is what i did.

1) Get the idea of your app in place and get the code ready. (apart from DropBox integration part)

2) You need to register yourself on DropBox to be able to use their API`s.

3) You have to add an app there. This will give you an app key and an app secret. There is a small trick though. DropBox doesn’t allow you to spread you app without their permission. So with the Keys you just got, you can only use it for development. When you think your app is ready to be distributed, you have to pass it through them to be checked for their standards and best practices.

4) Assuming you have your app registered, you should download the DropBox SDK. This includes the libraries required to use DropBox and it also includes an example app.

5) Go through the example app. Its pretty decent. It doesn’t showcase all the functionality available though. You can find out what all you can do with the API here.

This is all you need to get started. After this point, its all you and your app.

How i did it comes next.

One problem with DropBox API is the authentication screen is to created by you. You ask the user for username and password. You pass them along to the respective authentication API. Its not a very good way to do it as the programmer can save the usernames and passwords on the go. Its not allowed though its not clean by any standards.

The API itself is damn simple and easy to use, with functions like “put(file, path)” to put a file in your DropBox and “get(file, path)” to get a file from your DropBox. The problem i faced was to keep a user logged in even as the activities change and not to ask the user to enter his credentials again. But i guess it was more of a lack of knowledge on my side then the problem with the SDK. Once i figured out that a session class can do the job, it was more or less about implementing the session class. Still i feel the ease to as we have in Facebook API is missing. There is a lot of scope to do better and i hope things are in the pipeline. Here are a few screen shots of how i solved my problem of using DropBox for saving a single or multiple photos.

There is still work to be done on the app. But as they say, its the Journey that matters the most, result is just a byproduct.

Testers and Android

Continuing to my last post. Today i want to discuss how to make android apps which are stable, fast and efficient on resources. By now we should understand, mobile platforms are different and need specific tools as well. But whats common is, the need to optimize resource utilization. Again, like for iOS, we discuss the following topics for Android.

  1. Feature Testing
  2. Automation
  3. Profiling for leaks
  4. Profiling for CPU Usage
  5. Profiling for memory usage
  6. Allocations

Before you start reading further, i recommend reading abut the instrumentation class in Android documentation and DDMS. DDMS is a great tool provided by android specifically to profile your application and is for our good luck, very nicely integrated in Eclipse.

Feature Testing is usual manual testing. It doesn’t require any tools and so is the same as how you do it on Desktop Application or on iOS.

Automation : There are many tools out there to do automation on android. AutoAndroid, SeeTest, Calculon, Robotium and many more may be. This image taken from Vendor Benchmarking depicts nicely the comparison of the first three tools.

I would personally say, Robotium, having used it, is very easy to start with. Being a library so can be imported directly to your project. You can also create a separate test project along side your app. This is the normal way of using it. In order to use it for one click automation, you need it be a totally independent project. And so you need to write a wrapper above Robotium which can be bit of a pain. All the above mentioned 4 automation tools solve different problems and you need to pick one based on your product and your requirement. This goes without saying that all of these are black box testing tools and may or may not require maintenance as you go along developing.

Lets go to profiling, Leaks in your android are hard to find. I couldn’t find any useful tool out there to successfully monitor leaks on android. There is no equivalent of Instrument Leaks of iOS for Android. But there are other ways you can try and monitor. Instrumentation class provides us access to the memory usage of your app at any point of time. You just need to make a call and you can get the memory usage. Now using this function you can track the memory usage before and after the code you want to monitor. I understand its hard to find small leaks through this approach but its the best i got. Let me know if you find something better :).

While we are on memory usage. Lets go through memory utilization as well. There are many many ways to get to know your apps memory utilization. DDMS is the easiest, just select the DDMS view and your app from the left side pane. Then there is Instrumentation class, you can use it to track the memory utilization from your code. Then there is another way, your adb shell. You can use many commands to do so, top, dumpsys meminfo proc, procrank, vmstat. There is another tool named smem but you have to separately install it.The tricky part is, once you run the above commands, we get many memory values and its not very clear which one is useful

  • Vss = virtual set size
  • Rss = resident set size
  • Pss = proportional set size
  • Uss = unique set size

Different command line functions would give different outputs.

Because large portions of physical memory are typically shared among multiple applications, the standard measure of memory usage known as resident set size (RSS) will significantly overestimate memory usage. PSS instead measures each application’s “fair share” of each shared area to give a realistic measure of the activity of a system during boot. Hence PSS is our best shot for the memory usage by our app. I use procrank as it directly gives me the PSS value. Sometimes if you need more in depth output of dirty pages, you should use dumpsys meminfo.

Profiling for CPU. This is a bad one as i know only one way to do it. Use the top command and see the cpu usage. It works great for me tough because thats all i am looking for :).

Allocations again is something which can be done in multiple ways. I particularly like the DDMS solution for this. You can also use dmtracedump.exe and traceview. Whats good about android allocations is, you can create a dump file for the period you were monitoring your app for, and store it to be viewed later or used later or compared later. its an amazing debugging and testing tool and you should definitely read more about it.

All along the way i have assumed you have the knowledge of what is logcat and how to use it. Its basically a console output of what your device is doing. If you are reading this, you must already understand that for mobile testers, you need to get close to the product from the start and just UI level and feature testing is not enough.

I hope this was helpful. In case i mentioned something wrong or you want to ask anything, drop me a mail at maheshgattani@gmail.com

Experiment with Android

So today`s post is about my first experiment with android development. Its like they say “The best way to learn is to do it yourself” or “The first step is the most hard to take” or in my words “to be the best, you have to pass through good and better first”.

Coming to the app and what i went through. The app is as simple as it can be, A Facebook album viewer for you and your friends. Easy to start with, it allowed me to learn two things, Android app development and Facebook SDK for android. Lets talk about each of them.

Android: Oh My, if you have tried your hands on iOS development, it might not be so easy to just switch. The first and the easiest part in iOS is to create your views. You start the Interface Builder and its just drag and drop, as easy as it sounds (well for simple apps atleast). But in android, the drag and drop thing doesnt work as simply, you have to write most of the things in the xml file manually. That`s a pain. And doing it for all the activities takes a lot out of you.

After that things are a lot simpler and similar to the way you code anything mobile. There are lot of view available and you can use any number of them on a single activity. You can hide the not needed ones, create views on fly or remove them. If you are down with the UI, its more about the concept then the code.

A simple UI View can look like this with some image, some button and some text

And a bit more complex can look like this: an image, multiple texts, gallery view, list view.

It takes time to get used to the way Activities behave, how to navigate between them, how to communicate between them. This was the second problem i faced. Once you figure this one out, the concept of adding view becomes simple. I actually became so comfortable that i added multiple new views against my earlier mocks.

Next problem i faced was how to let views interact with each other. What if you want one view to be updated if some changes are made to some other view? This is actually very simple using adapters (notifydatasetchanged() method)and comes in very handy to improve your user experience. In this activity, i was changing the gallery view if the list view changed, and changing the list view if the gallery view changed.

You need to remember, views and activities are two different things. An activity can contain any number of views. And a view can be used as an activity.

You can go through the code at https://github.com/maheshgattani/DownloadFacebook

Now the Facebook SDK. Man o Man, this is the reason Facebook can never be the next Orkut. They just made it so simple for developers. Now its not only Facebook people working for them, they have people like me also. Its just the simplest thing. Go to Facebook Developers page, setup a test app, get an app ID, download the SDK, and you can start writing code. The first thing i figured when i started writing this app was Facebook SDK is the least of my worries, because its just so simple and easy to use. and what more, Facebook has provided tools to test a few things while you are working on them.

Android vs iOS

I have been having these long discussions with friends and colleagues about android and iOS. Which one is better? Which one has a better future? Which device to buy right now, IPhone or Android device? I have heard so many arguments, arguments from hard core android fans and arguments from apple fans.

I for one, believe iOS is in a very very good state as compared to android. Also, when we say iOS, we can assume the device and the OS as the same because of the integration apple provides. When it come to Android, we have to think of the OS separately and of device separately. But lets see what each of them has to offer.

For Developers?

When we talk about the developer view, we need to take care of 2 things. What all we can do and how easily we can do that?

Android is a clear winner in what all you can do. Being an open source, it provides such an environment that you can essentially do anything if your device permits it.

iOS is a restricted environment. Somethings are not meant to be changed because the OS is designed that way (read Flash, Any app which can be used to run other programs is not allowed). Apple has a screening process, so just because you developed an app doesn’t mean you can put it on App store. You need to follow some strict guidelines only then you can assume apple would approve your app.

iOS is a winner when it comes to how easily can you do something.

To start with, the toughest part being creating the UI experience. iOS development SDK provides you with a tool for interface building. A very easy to use and effective tool. MVC(Model-View-Controller) implementation might be a bit tricky to start with but is very effective as well. The code goes in Objective C which is just another OOP language and you tend to get used to it as you use it. Also since there are only a small set of devices with iOS, building an app on it takes a lot less of thinking as to what all devices you support.

Android lacks heavily in terms of UI experience. Without any standard interface builder, it is a haunting task to get your UI as you want it to look. Writing whole or part of views in XML might not suit all the users. The code goes in Java which is very well known. Also, with so many android devices in market, it might be a painful experience to figure out which all devices you want to support. And since the OS and device are not so well linked, you also have to think about the device specification when you are building an app.

For Users

For users, things boil down to ease of use, User experience and ability to do more.

iOS, for me, is the winner when it comes to ease of use. The devices with iOS gives you an easy feel to everything. Be it accessing things, be it closing things, be it downloading music and videos, be it downloading new apps, almost everything. For a person who is not very technical, iOS is far far easy to use then it android counterpart.

User experience, again iOS. This is true because of the tight integration between the device and the OS. This is an easy one, just try playing a game in android and same on iOS, the difference is visible. Also, android as a platform isnt as stable as iOS is. The apps on android arnt as stable as they are on iOS (read apple`s filtering process).

Ability to do more? This is tricky, mainly because android as a package does provides you more stuff to do. But iOS provides you more app to do search and use from. The difference isn’t very apparent. On the contrary, you can do almost anything on both the OS`s. You would find app for everything on both the platforms. As of now, you have many more devices to select from in android and many more app to select from in iOS. My vote goes to iOS, being more stable and with lot more apps.

Going Ahead

Both the platforms, iOS and android, have great future. iOS 5 has been announced and it includes lot of nice features. Android 3.1 (Ice cream sandwich) is out which is the first in line to supports both tablets and handsets. Though Android is behind iOS right now, i expect it to match iOS sooner than later. With contributions from everywhere, android is developing fast. We have Microsoft “Mango” coming. Mobile field is very exciting right now and rapidly progressing.

What to buy?

My vote goes to iOS mainly because of the tight integration. The iOS devices are high end when it comes to specs. The user experience is amazing as compared to only good for android. Android OS depends a lot on device hardware. Samsung has done some rights with Galaxy series. It basically boils down to

“Freedom of choice OR freedom from choice”

read

“Android OR iOS”