yeemobile
Dalvik JIT
五 26th
[This post is by Dan Bornstein, virtual-machine wrangler. — Tim Bray]
As the tech lead for the Dalvik team within the Android project, I spend my time working on the virtual machine (VM) and core class libraries that sit beneath the Android application framework. This layer is mostly invisible to end users, but done right, it helps make Android devices run smoothly and improves developer productivity.
The 2.2 release is particularly pleasing to me, as it is the first release since before 1.0 in which we have been able to deliver significantly new VM technology. And unlike much of what my team and I do, it is something that can be experienced directly by end users.
“Dalvik” isn’t exactly a household word (at least in my country), and most people wouldn’t know a virtual machine if it hit them in the face, but when you tell them you were able to make their existing device work better — run faster, use less battery — they will actually take notice!
What Makes This Possible?
We added a Just In Time (JIT) compiler to the Dalvik VM. The JIT is a software component which takes application code, analyzes it, and actively translates it into a form that runs faster, doing so while the application continues to run. If you want to learn more about the design of the Dalvik JIT, please watch the excellent talk from Google I/O 2010 given by my colleagues Bill Buzbee and Ben Cheng, which should be posted to YouTube very soon.
To be clear, the differences aren’t always dramatic, nor do they apply uniformly to all applications. Code that is written to run the CPU all-out can now do more in the same amount of time (running faster), and code that is written to be rate-limited can get its work done using less time and less of the CPU (using less battery). On the performance front in particular, we have seen realistic improvements of 2x to 5x for CPU-bound code, compared to the previous version of the Dalvik VM. This is equivalent to about 4x to 10x faster than a more traditional interpreter implementation.
The team is proud of our new JIT in general, but we are especially proud of two aspects of it:
Many previous JIT implementations react slowly, delivering performance improvements only after a long warm up period. In the extreme, it can be minutes or even hours before the code is fully up to speed. On the other hand, the Dalvik JIT reacts quickly, so that mere moments after you hit the “Start” button on your favorite game, you are already benefiting from the work of the JIT.
We are also very pleased with how little memory the JIT uses. The code for the JIT itself is well under 100k, and each process that the JIT runs in will typically only use another 100k or so of RAM. On the current generation of Android phones, device users won’t even notice this additional memory usage; on my own phone, I can still have literally dozens of applications warmed up in memory and ready to go.
The Dalvik team isn’t resting on its laurels, either. We are hoping to see the Dalvik JIT deployed on many devices in the coming months. Looking forward, the team has an endless list of ideas for making the VM and library code better, which we are diligently working on.
Wireframe Sketcher & Android
五 25th
From a project management perspective it is a good practice to have UI Mockups designed before the real implementation starts. With the UI Mockups having ready, you can discuss with the customer if that is going to satisfy the real needs, and you can also discuss inside your development team, if the UI implementation is feasible or not. If you can settle those things before the implementation, you can save huge amount of refactoring, that usually starts with statements like “This takes too much space on screen, can we have it on a separate screen?”, which may also have a large impact on the application architecture. This lesson is also valid for the world of Android development, where the Wireframe Sketcher with its Android stencil set is a perfect tool for fast and informative UI Mockup drawing.
Connecting to MySQL database
五 25th
| The most spread method to connect to a remote MySQL database from an android device, is to put some kind of service into the middle. Since MySQL is usually used together with PHP, the easiest and most obvious way to write a PHP script to manage the database and run this script using HTTP protocol from the android system. |
|
We can code the data in JSON format, between Android and PHP with the easy to use built in JSON functions in both languages.
I present some sample code, which selects data from a database depending on a given condition and creates a log message on the android side with the received data.
Lets suppose that we have a MySQL database named PeopleData, and a table int created, with the following SQL:
-
CREATE TABLE `people` (
-
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
How to have a default database
五 25th
If you want to include a database with initial data in your apk, you have to insert the database file into the projects assets folder, then programmatically check if the database, and if it does not exists copy the one from the assets.
You will need a function to check if the database exists, fox example:
If the check shows that the the database does not exist, a function like this will copy it:
-
// Open your local db as the input stream
-
// Path to the just created empty db
How to display an AlertDialog in your Android application
五 25th
Here is an example of an applacation, that illustrates how you can create a simple AlertDialog. The dialog can display maximum three buttons.

How to display a custom dialog in your Android application
五 25th
How to display a custom dialog in your Android application
Yesterday Jozsi showed you, how to make an alert dialog, today I’m going to show you, how to make a custom dialog/popup window.
Sometimes, it’s better to make your own dialog, because this way, you can display whatewer you want., the way you want it.
First, make your own layout, with the needed elements. Here, I’m going to use two buttons, a textview inside a scrollview, and an imageview…
How to avoid OutOfMemory (OOM) Exception using Bitmaps (Solved)
五 25th
Step 1.
First thing I want you to think about is that do You really need to use Bitmaps?
If the answer is No, go to step 2.
Otherwise, think again.
Ok, Let me explain it. I needed Bitmaps to get the width of the images, to create an ImageAdapter for my Gallery. As far as I know, there’s no other way to do that. So I used Bitmaps, and even if I recycled them, once in a while it stopped with the message: DDMS: OutOfMemory .. Phone: Force Close..
Not to speak about how laggy your app will be if you are using Bitmaps..
I’ve spent 2 weeks to find a solution for this problem, but I couldn’t find any usable of them. Then I thought, I try not using Bitmaps anymore. So I have to find another way to get the width of images. Unfortunately, it’s just a workaround, but it works so who cares, right?
I can determine widths with a PHP script, store it in my existing database. After I did that, everything was working properly.
How to play video and audio on Android
五 25th
There is more than one way, to play media files on an Android phone, let me show you two of them.

Audio:
MediaPlayer is the easier way, if you just want to play an audio file in the background, somewhere in an appliaction. There are no ui controls here, but of course you can use MediaPlayer.stop(), play(), seekTo() ,etc. Just bind the needed functions to a button, gesture, or event. As you can see, it also throws a lot of exceptions, which you need to catch.
-
//set up MediaPlayer
-
MediaPlayer mp = new MediaPlayer();
-
-
try {
-
mp.setDataSource(path+"/"+fileName);
-
// TODO Auto-generated catch block
-
e.printStackTrace();
Store images/files in database
五 25th
Hoever the practice is to store them normally and save the access route (Uri), sometimes it can be handy to store files/images completely in database.
In sqlite database there are only a few data types, so its easy to choose: files can be stored in a text as a ByteArray.
Lets see a sample code, where we download an image from the Internet then store it in the local database:
-
//where we want to download it from
-
//open the connection
-
//buffer the download
-
ByteArrayBuffer baf = new ByteArrayBuffer(128);
-
//get the bytes one by one
-
int current = 0;
-
while ((current = bis.read()) != -1) {
-
baf.append((byte) current);
-
}
-
-
//store the data as a ByteArray
-
//db is a SQLiteDatabase object
-
ContentValues dataToInsert = new ContentValues();
Sony to announce Android based TV – State of the Android nation
五 25th
The news is hot. According to Bloomberg Sony will announce an Android based television in May.

I assume that this action will open up another front for Android Application Development.
The Android platform looks pretty bright from development point of view. Within a short time the one phone (G1) OS has grown into a significant player in the operating system market.
Statistics clearly show that Android is heavily gaining market share in the smartphone market. That is already a stable trend beyond discussion.
