Showing posts with label technotes. Show all posts
Showing posts with label technotes. Show all posts
06 October 2011
Google App Engine Blog: Google Cloud SQL: Your database in the cloud
Google App Engine Blog: Google Cloud SQL: Your database in the cloud: Cross-posted from the Google Code Blog One of App Engine’s most requested features has been a simple way to develop traditional database-d...
04 May 2011
What is an "application/octet-stream" MIME attachment
A MIME attachment with the content type "application/octet-stream" is a binary file. Typically, it will be an application or a document that must be opened in an application, such as a spreadsheet or word processor.
No matter what kind of file it is, an application/octet-stream attachment is rarely viewable in an email, Usenet, or web client.
In addition to the generic application/octet-stream content type, you may also encounter attachments that have different subtypes (e.g., application/postscript, application/x-macbinary, and application-msword). They are similar to application/octet-stream, but apply to specific kinds of files.
26 April 2011
Vim Tip: Copy and paste into the editor
- Let's see what "set paste" can do for you -- saving you a lot of time.
27 March 2011
[Technote] Saving states from Android Activities
When you start to develop applications on Android devices, managing Activity states definitely is the first major thing to master in order to create reliable, robust Android apps. Here I will simply go through what I have found during developing Android apps myself:
First, you have to think carefully what states are necessary to be retained when Android Activity is destroyed. Usually, the less states you save, the better (because that reduces your Activity start-up time as well as destroying time). For instance, you might not need to save the 'look' of View, because it can always be redrawn/recomputed every time when an Activity comes to live; instead, saving some states necessary for Android to recompute that look, i.e., the current position of the cursor on screen.
Second, you can then think about HOW to save states after determining what to save. Generally, there are three ways to do it (not including saving data on Android internal filesystem or SD card):
- Using
Bundleto save primitive typed (check forBundleAPI), temporary data. - Using
SharedPreferencesto save primitive typed, persistent data. - Using
onRetainNonConfigurationInstanceto save temporary object instances.
To retrieve data you saved,
onCreate is a good place for your activity to reload states. According to my experience, onCreate is probably and mostly what you really want, not onResume or onStart otherwise.A side note for the above: the easiest and best way to test if your management of Activity's life cycle is correct, is to change the orientation of the screen. It should not crash and the behavior should be the same as before orientation.
Last, sometimes what we really want is to have some simple communication mechanism between activities (i.e., the calling activity and the callee activity) instead of saving states, how to achieve that? In the caller activity, call the callee with
startActivityForResult, and also implement the onActivityResult method. Then, in the callee, remember to call setResult to set the result to be returned, before the activity is finished.17 March 2011
[Techonote] Java container anomaly
You can assign a pointer of type sub to a pointer of type super (this is simply a is-a relationship). However, you cannot assign a pointer type
container(sub) to a pointer of type container(super) (e.g. List<String> IS NOT a List<Object>).15 March 2011
[Technote] Caution for Java auto-unboxing
Auto unboxing does not work with
== or !=.For example:
Two List<Integer> a and b,
a.get(0) == b.get(0) -- does not unbox. Instead, it does an == pointer comparison between the two Integer objects.To get what you want, you will do the following:
Use
a.get(0).intValue() == b.get(0).intValue() to force the conversion to int. Or you could write a.get(0).equals(b.get(0)) which works for String, Integer, etc.28 February 2011
18 February 2011
[Technotes] invalidate() method
In android system, the class
View (android.view.View) is an important interface for rendering UI objects. Inside it, a method called invalidate() plays a key role.The function of
invalidate is simple, it marks a region on the view to be 'dirty', which tells the android system that region must be redrawn soon in the near future. The region can be the whole View or just a designated region passed to invalidate. And obviously, invalidating only a small portion of the view can have some performance advantages for the UI system. Therefore, make sure you use invalidate() wisely!Also, an important point: never call any drawing functions except in the
onDraw( ) method (a method of class View). Instead, you use the invalidate( ) method to mark rectangles as dirty. The window manager will combine all the dirty rectangles at some point in the future and call onDraw( ) again for you. The dirty rectangles become the clip region, so screen updates are optimized to only those areas that change.06 February 2011
[Tech notes] How to delete objects in Java?
There is no
delete or free keyword in Java. The only thing that can collect the unreferenced memory chunk is garbage collector (GC). To take advantage of that, the best practice is to 'null' out your object reference whenever you want the GC to free that object:
MyObject a = new MyObject();
... /* Do something with object a */
a = null; /* Tell GC to free the memory referenced by a! */
01 February 2011
[Tech notes] Android API levels
The following table specifies the API Level supported by each version of the Android platform:
Development Considerations
Application forward compatibility
Application backward compatibility
| Platform Version | API Level |
|---|---|
| Android 2.3 | 9 |
| Android 2.2 | 8 |
| Android 2.1 | 7 |
| Android 2.0.1 | 6 |
| Android 2.0 | 5 |
| Android 1.6 | 4 |
| Android 1.5 | 3 |
| Android 1.1 | 2 |
| Android 1.0 | 1 |
The API Level identifier serves a key role in ensuring the best possible experience for users and application developers:
- It lets the Android platform describe the maximum framework API revision that it supports
- It lets applications describe the framework API revision that they require
- It lets the system negotiate the installation of applications on the user's device, such that version-incompatible applications are not installed.
Applications can use a manifest element provided by the framework API —
uses-sdk — to describe the minimum and maximum API Levels under which they are able to run, as well as the preferred API Level that they are designed to support. Development Considerations
Application forward compatibility
Android applications are generally forward-compatible with new versions of the Android platform.
Because almost all changes to the framework API are additive, an Android application developed using any given version of the API (as specified by its API Level) is forward-compatible with later versions of the Android platform and higher API levels.
Application backward compatibility
Android applications are not necessarily backward compatible with versions of the Android platform older than the version against which they were compiled.
Reference
Reference
26 January 2011
[Tech notes] Android executable file - .apk
"Android applications are written in the Java programming language. The compiled Java code — along with any data and resource files required by the application — is bundled by the aapt tool into an Android package, an archive file marked by an .apk suffix. This file is the vehicle for distributing the application and installing it on mobile devices; it's the file users download to their devices. All the code in a single .apk file is considered to be one application."
The above is just an except from the Android dev guide.
Android aapt tool
aapt stands for Android Asset Packaging Tool and is included in
tools/ directory of the SDK. This tool allows you to view, create, and update Zip-compatible archives (zip, jar, apk). It can also compile resources into binary assets.Most important of all, build scripts and IDE plugins can utilize this tool to package the apk file that constitutes an Android application.
To use aapt directly, open a terminal, go to the tools/ directory, and run the command (for linux and Mac OS X):
$ ./aapt
22 January 2011
[solved] Unparsed aapt error(s)! Check the console for output
Today I wrote some codes for my Android application as usual, and I found a parsing error that says:
"Unparsed aapt error(s)! Check the console for output"However, I didn't see any errors after checking all the files. So what is going on here? It happens when some
*.out.xml files are generated before the entire project gets built for execution. How can this happen? It happens when you run the application when in a resource file.The solution to this issue is simple: make sure you clean any post-built files before building your application for a run. To achieve this, go to Project --- Clean in the Eclipse menu and it will work again. Or, you can just delete
R.java file. It will get created again and the problem is solved.21 January 2011
[Tech Notes] Android basics II - Android SDK building blocks
A few objects are defined in the Android SDK that every developer needs to be familiar with. There are the building blocks of your android applications.
The most important ones are:
The most important ones are:
Activities, Intents, Services, and Content Providers.Activities - represents a user interface screen. Applications can define one or more activities to handle different phases of the program.Intents - a mechanism for describing a specific action, such as "pick a photo". Everything has to go through Intents before creating activities or actions.Services - a service is a task that runs in the background without the user's direct interaction, similar to a Unix daemon.Content Providers - a set of data wrapped up in a common API to read and write it. This is the best way to share global data between applications.
[Ubuntu] Change desktop launcher icon
How to change desktop launcher icon? It is surprisingly easy, check here.
[Tech Notes] Android Basics I - Android System Architecture
Android system architecture:
Get get the big picture of system architecture, please check out this documentation online. To sum up, there are four primary layers for the software system - Linux Kernel, Libraries and Android Runtime, Application Framework, Applications and Widgets.
This concept is essential because you need to know what layer (s) you will be dealing with when developing apps, making your own frameworks and libraries or even modifying Linux Kernel. For application development, you will not see Linux Kernel, all you can see is Application Framework and Application layers.
![]() |
| Android System Architecture |
Subscribe to:
Comments (Atom)
