Kamis, 09 Desember 2010

Saving Data Safely

Jika anda baru pertama kali berkunjung ke blog ini, Silakan kasih Komentar untuk artikel yang anda baca.

With the advent of Gingerbread, were going to be streaming a series of posts in this space most the aspects of Android 2.3 that developers should tending about. One abstract that developers should tending most more than anything else is not losing data. The rules are dynamical slightly as Gingerbread arrives, so I intellection that would be a good starting point. I didnt write this; I pulled it together from the table of an email arrange involving Android engineers Brad Fitzpatrick, Dianne Hackborn, Brian Swetland, and Chris Tate.

The question is: how do you make rattling trusty your datas been written to persistent storage? The respond involves a low-level grouping call named fsync(). Old C programmers same me mostly scholarly this the hard artefact back in the Bad Old Days; in 2008 at OSCON I immensely enjoyed Eat My Data: How Everybody Gets File IO Wrong by histrion Smith; I've included a picture I took of one of his slides.

The think this should be of concern to Android developers is that with 2.3, an increasing equilibrium of devices, notably including the Nexus S, are going to be moving from YAFFS to the ext4 filesystem, which buffers much more aggressively; thusly you requirement to be more assertive most making trusty your accumulation gets to permanent hardware when you poverty it to.

If you just ingest SharedPreferences or SQLite, you crapper relax, because weve made trusty they Do The Right Thing most buffering. But if you hit your possess on-disk format, keep in nous that your accumulation doesn't actually consistently accomplish the flash chip when you write() it or even when you close() it. There are several layers of buffering between you and the hardware! And because of ext4 buffering policy, any POSIX guarantees that you intellection you had before (but actually didn't), you especially don't hit now.

Some Android devices are already streaming non-YAFFS filesystems, but as we brought up the Nexus S, buffering issues hit actually bitten us a couple of nowadays in framework code. When the Gingerbread source cipher becomes available, youll find lots of examples of how file I/O should be done.

To start with, for raw accumulation study using one of the coetaneous modes of java.io.RandomAccessFile, which verify tending of calling fsync() for you in the pertinent way. If you cant, youll poverty Java cipher that looks something same this.

public static boolean sync(FileOutputStream stream) { try { if (stream != null) { stream.getFD().sync(); } convey true; } grownup (IOException e) { } convey false;

In whatever applications, you strength even poverty to analyse the convey status of the close() call.

Now of course, there are digit sides to this story. When you call fsync() and obligate the accumulation onto storage, that crapper be slow; worse, unpredictably slow. So be trusty to call it when you requirement it, but be careful not to call it carelessly.

Background datum if you poverty to know more:

  • ext4 and accumulation loss by Jonathan Corbet.

  • ext4 vs fsync, my verify by Alexander Larsson.

  • Dont fear the fsync! by Ted Tso.


Thanks
basyar.com

Senin, 06 Desember 2010

Android 2.3 Platform and Updated SDK Tools

Jika anda baru pertama kali berkunjung ke blog ini, Silakan kasih Komentar untuk artikel yang anda baca.

Today we're announcing a newborn version of the Android papers Android 2.3 (Gingerbread). It includes many newborn papers technologies and APIs to hold developers create enthusiastic apps. Some of the highlights include:

Enhancements for game development: To improve coverall responsiveness, weve added a newborn concurrent substance holder and optimized the platforms coverall circumstance handling. Weve also presented developers autochthonous access to more parts of the system by exposing a broad set of autochthonous APIs. From autochthonous code, applications crapper today access input and device events, EGL/OpenGL ES, OpenSL ES, and assets, as substantially a newborn framework for managing lifecycle and windows. For fine motion processing, developers crapper ingest individual newborn device types, including gyroscope.

Rich multimedia: To provide a enthusiastic transmission environment for games and another applications, weve added hold for the newborn recording formats VP8 and WebM, as substantially as hold for AAC and AMR-wideband encoding. The papers also provides newborn audio effects much as reverb, equalization, headphone virtualization, and bass boost.

New forms of communication: The papers today includes hold for front-facing camera, SIP/VOIP, and Near Field Communications (NFC), to let developers allow newborn capabilities in their applications.

For a complete overview of whats newborn in the platform, see the Android 2.3 Platform Highlights.

Alongside the newborn platform, we are emotional updates to the SDK Tools (r8), NDK, and ADT Plugin for Eclipse (8.0.0). New features include:

Simplified debug builds: Developers crapper easily create debug packages without having to manually configure the applications manifest, making workflow more efficient.

Integrated ProGuard support: ProGuard is today packaged with the SDK Tools. Developers crapper today obfuscate their code as an desegrated conception of a promulgation build.

HierarchyViewer improvements: The HierarchyViewer tool includes an updated UI and is today reachable directly from the ADT Plugin.

Preview of newborn UI Builder: An primeval promulgation of a newborn visual layout application lets developers create layouts in ADT by dragging and dropping UI elements from contextual menus. Its a impact in advancement and we impart to iterate quickly on it.

To get started nonindustrial or investigating applications on Android 2.3, meet the Android Developers site for information most the Android 2.3 platform, the SDK Tools, the ADT Plugin and the newborn NDK.

Check out the recording below to learn more most the newborn developer features in Android 2.3.


Thanks
basyar.com