Thursday, May 21, 2009
From Android to AppEngine
So I've finished the first (crude) iteration of my Android app, and am now moving on to creating a web application that will act as middleware.
Why a web app? Well. My Android app basically consists of grabbing the phone's current location, adding a picture and notes if the user so desires, and uploading this data to a web site. (I'm actually thinking of hiving off this basic functionality as a "Scout API" down the line, and releasing the code for future Android novices; I'm guessing that "hey, let's have people register / comment on the locations of $things1 when they come across them!" apps out there.
But a phone has very limited resources, from CPU to storage, and an annoying UI; so rather than make the user do everything on the phone, far better just to grab the on-the-spot data and do whatever further processing is required on a web site far, far away.
So I've started playing with Google AppEngine. Thus far it looks very easy, very powerful, and integrates seamlessly with Google Accounts, so you don't have to roll your own user infrastructure (and so you get locked into theirs....) It's also currently only available in Python, but what the hell, I was getting bored of Java anyway, right? More on AppEngine in the next post.
Other things I learned about Android:
Don't tug on SurfaceView's cape
The camera API is surprisingly simple, and Android comes with a SurfaceView which, among other things, lets you easily display a real-time camera preview (if you subclass it.) My intent was to have the "take picture" and "see preview" user actions be part of the same Activity - ie, when the user selects "take picture", stop showing the preview, and instead draw that snapshot on the SurfaceView.
This did not work well. SurfaceView is a very weird artifact and a difficult one to play with. After about two hours of beating my head against the problem I wisely decided to create a "ShowPicture" Activity with an ImageView, which was much simpler, and worked much better. Moral: don't overload any given Activity. Keep 'em simple, stupid.
Also, because I subclassed SurfaceView into CameraView (as per the Camera example in the API Demos that come with the SDK) I had to have a two-level callback structure: in my Camera Activity, there was a TakePicture button, which called "takePicture()" in my CameraView, which instructed its Camera to snap a shot. Then there were three callbacks in CameraView (one to indicate success, one for the RAW, one for the JPEG) and in turn I had to callback Camera. This works fine, but is a little more convoluted than I'd like.
Be careful about where you are in the stack
Creating a new ShowPicture activity did create a new problem, in that the user navigation might be "edit note -> take picture -> see preview" and might be "edit note -> see existing picture -> take new picture". In the first case, after you take the picture, you want to open a new SeePicture Activity; in the second, you want to return to the existing one. The solution was to pass a flag in the Intent that goes to the Camera activity, indicating whether you're taking a new picture or replacing an existing one.
Always save when leaving a window
In theory, Android could kill your app at any time, to conserve resources. It will probably notify you before it does so (see the Activity Life Cycle.) So it's best to save all user-modified information in "onPause()", just on case. This incentivizes you to keep your database structures very simple.
This does create the cancellation problem as per my last post, but I think that's the lesser of two evils.
GPS is busted in the emulator
The emulator's mock location providers basically don't work. Fortunately, this basically doesn't matter, as you can roll your own if you really care.
1For the record, I hate Perl with an abiding passion, but the $ prefix remains the best way to signify "this is a variable" in prose.
Why a web app? Well. My Android app basically consists of grabbing the phone's current location, adding a picture and notes if the user so desires, and uploading this data to a web site. (I'm actually thinking of hiving off this basic functionality as a "Scout API" down the line, and releasing the code for future Android novices; I'm guessing that "hey, let's have people register / comment on the locations of $things1 when they come across them!" apps out there.
But a phone has very limited resources, from CPU to storage, and an annoying UI; so rather than make the user do everything on the phone, far better just to grab the on-the-spot data and do whatever further processing is required on a web site far, far away.
So I've started playing with Google AppEngine. Thus far it looks very easy, very powerful, and integrates seamlessly with Google Accounts, so you don't have to roll your own user infrastructure (and so you get locked into theirs....) It's also currently only available in Python, but what the hell, I was getting bored of Java anyway, right? More on AppEngine in the next post.
Other things I learned about Android:
Don't tug on SurfaceView's cape
The camera API is surprisingly simple, and Android comes with a SurfaceView which, among other things, lets you easily display a real-time camera preview (if you subclass it.) My intent was to have the "take picture" and "see preview" user actions be part of the same Activity - ie, when the user selects "take picture", stop showing the preview, and instead draw that snapshot on the SurfaceView.
This did not work well. SurfaceView is a very weird artifact and a difficult one to play with. After about two hours of beating my head against the problem I wisely decided to create a "ShowPicture" Activity with an ImageView, which was much simpler, and worked much better. Moral: don't overload any given Activity. Keep 'em simple, stupid.
Also, because I subclassed SurfaceView into CameraView (as per the Camera example in the API Demos that come with the SDK) I had to have a two-level callback structure: in my Camera Activity, there was a TakePicture button, which called "takePicture()" in my CameraView, which instructed its Camera to snap a shot. Then there were three callbacks in CameraView (one to indicate success, one for the RAW, one for the JPEG) and in turn I had to callback Camera. This works fine, but is a little more convoluted than I'd like.
Be careful about where you are in the stack
Creating a new ShowPicture activity did create a new problem, in that the user navigation might be "edit note -> take picture -> see preview" and might be "edit note -> see existing picture -> take new picture". In the first case, after you take the picture, you want to open a new SeePicture Activity; in the second, you want to return to the existing one. The solution was to pass a flag in the Intent that goes to the Camera activity, indicating whether you're taking a new picture or replacing an existing one.
Always save when leaving a window
In theory, Android could kill your app at any time, to conserve resources. It will probably notify you before it does so (see the Activity Life Cycle.) So it's best to save all user-modified information in "onPause()", just on case. This incentivizes you to keep your database structures very simple.
This does create the cancellation problem as per my last post, but I think that's the lesser of two evils.
GPS is busted in the emulator
The emulator's mock location providers basically don't work. Fortunately, this basically doesn't matter, as you can roll your own if you really care.
1For the record, I hate Perl with an abiding passion, but the $ prefix remains the best way to signify "this is a variable" in prose.
Labels: Android, AppEngine, CanvasView, Java, SurfaceView
Comments:
Thanks for posting this.I got many helpful information from your blog.
Android Training in Velachery
Android Training in T nagar
Android Training in Anna nagar
Android Training in Porur
Android Training in Tambaram
Android Training in OMR
Android Training in Adyar
Android Training in Vadapalani
Android Training in Thiruvanmiyur
<< Home
google app engine now supports java, and therefore (more excitingly) a range of jvm languages. looking forward to playing with it myself, if i ever stop spending 15 hours a day in the offce
Thanks for posting this.I got many helpful information from your blog.
Android Training in Velachery
Android Training in T nagar
Android Training in Anna nagar
Android Training in Porur
Android Training in Tambaram
Android Training in OMR
Android Training in Adyar
Android Training in Vadapalani
Android Training in Thiruvanmiyur
Hi Very Nice Blog I Have Read Your Post It Is Very Informative And Useful Thanks For Posting And Sharing With Us.
Carpet Cleaning Sunshine Coast
Carpet Cleaners Sunshine Coast
Carpet Cleaning Sunshine Coast
Carpet Cleaners Sunshine Coast
Great Article! Keep on sharing the update with us.
Carpet Cleaning Brisbane | Carpet Cleaners Brisbane
Carpet Cleaning Brisbane | Carpet Cleaners Brisbane
Superb ! Your blog is incredible. I am delighted with it. Thanks for sharing with me more information.
Android training in anna nagar
Android Training in Chennai
Android Training in OMR
Python Training in anna nagar
Software testing training in T Nagar
Android Training in T Nagar
Digital Marketing Course in anna nagar
Spoken English Classes in Tnagar
Android training in anna nagar
Android Training in Chennai
Android Training in OMR
Python Training in anna nagar
Software testing training in T Nagar
Android Training in T Nagar
Digital Marketing Course in anna nagar
Spoken English Classes in Tnagar
Thanks for posting this.I got valuable information from your blog.
Carpet Cleaning Adelaide | Carpet Cleaners Adelaide
Carpet Cleaning Adelaide | Carpet Cleaners Adelaide
Nice blog! Thanks for sharing this valuable information
best selenium training in chennai
Selenium Training in Bangalore
Selenium Training in Coimbatore
Selenium course in Chennai
Software Testing Course in Chennai
Hacking Course in Bangalore
Best selenium Training Institute in Bangalore
best selenium training in chennai
Selenium Training in Bangalore
Selenium Training in Coimbatore
Selenium course in Chennai
Software Testing Course in Chennai
Hacking Course in Bangalore
Best selenium Training Institute in Bangalore
Get inspired by your blog. Keep doing like this....
Tally Course in Chennai
Tally Training in Chennai
Tally training in coimbatore
Tally course in madurai
Tally Classes in Chennai
Tally classes in coimbatore
Tally coaching centre in coimbatore
Tally training institute in coimbatore
Software Testing Training in Chennai
German Classes in Bangalore
Tally Course in Chennai
Tally Training in Chennai
Tally training in coimbatore
Tally course in madurai
Tally Classes in Chennai
Tally classes in coimbatore
Tally coaching centre in coimbatore
Tally training institute in coimbatore
Software Testing Training in Chennai
German Classes in Bangalore
Subscribe to Post Comments [Atom]
<< Home
Subscribe to Posts [Atom]
Post a Comment