Descargar-Android.com : Posts Comments - Android Market
  • Página principal

android apps

  • Descargar Merka Market [apk]
  • Aplicaciones [apk] Android Gratis
  • SuperGNES para android [Apk][Full][Gratis]
  • WhatsApp Messenger Android [Apk] [Gratis] [Android Market] [Español]
  • Descargar Juegos de Memes Apk
  • App 2 SD Pro .Apk 2.44 Android [Full] [Gratis]
  • Descargar InstantAmix Android [Apk][Full][Gratis]
  • Instalar Adobe Flash Player 10.3 en Android 2.1 y 3.0
I have a more than 2 years old - and quite popular - blog post about service binding and I thought I knew enough of Android services. Then I ran into a service binding pattern that I was not aware of before. I would like to clarify before I start that every alternative in this post "works" - meaning it does what it is intended to do on the Android versions released so far. Still, it seems that this hack I am going to present got into tutorials and books. I think there is a risk here that a good number of coders think about it as the right thing to do and not as a hack.

Click here to download the example program.

This is a version of the good old DualService presented in this blog entry. The main difference that the AIDL file has been removed and instead you will find this strange construct in DualService.java:

public class DualServiceBinder extends Binder implements ICounterService {
public int getCounterValue() {
return counter;
}
}

and in onBind:

public IBinder onBind( Intent intent ) {
return dualServiceBinder;
}

Now this DualServiceBinder "Binder derivative" is a strange thing. Binders are serialization-deserialization constructs that turn RPC invocations into byte streams and back. That byte stream can be sent through the Binder kernel driver and that's how interprocess communication works in Android. Binder derivatives are normally generated by the aidl tool. You can do it by hand but it is not for the faint of heart. Basically you have to implement transact/onTransact methods and serialize/deserialize your data by hand. If you follow my advice, you leave it to the aidl tool.

DualServiceBinder does none of it. It implements a plain Java interface (ICounterService) and exposes a plain Java method. On the other side, in DualServiceClient it justs casts the IBinder to ICounterService in the onServiceConnected method and invokes the method on it.

As you might have guessed, this is a hack. The author sidestepped entirely the Android IPC mechanism and abused two properties of the Android application model.

  • By default, the Android application manager loads activities/services/providers into the Dalvik VM running in the same Linux process.
  • Classes from the same DEX file (there is one DEX file per APK) are loaded by the same class loader.
These guys here do not use Binder at all. They need an IBinder implementation because of the onBind/onServiceConnected methods' contracts and Binder comes handy as it is an implementation of the IBinder interface. Other than that, the DualServiceBinder instance is just passed from the Service to the Activity without any IPC taking place. That is why it can be recasted to a simple Java interface and the method can be invoked without any IPC mechanism. The hack is actually faster than the AIDL-based implementation (as there is no serialization/deserialization, just in-memory parameter passing) but this approach is not supported in any way by the Android API contracts.

Do you think I found the hack in a shady, unsupported freeware? No, I found it in a book (actually, my attention was turned to this book by a fellow Android programmer). The book proposes another trick: the "service interface" of their Binder descendant exposes just a getService() method that returns a reference to the Service instance and later the Activity invokes public methods of the service directly, circumventing even their own tricky service interface.

I definitely think it is a bad idea to propagate this hack even though it works on the existing Android implementations and is somewhat faster than the regular, AIDL-based invocation.
Entradas más recientes Entradas antiguas Página principal
  • Nuevas Aplicaciones de Market Android

Aplicaciones Android Populares

  • TSF Shell Pro 3D .Apk Android [Full] [Gratis]
    TSF Shell Pro 3D .Apk Android [Full] [Gratis] Gratis el APK de TSF Shell Pro 3D Android full, podras descargar TSF Shell .Apk full Android y...
  • BBM v.6.2.0.33 BETA DISPONIBLE
    La aplicación BlackBerry Messenger ha recibido una actualización a la versión 6.2.0.33 para los usuarios de la ZONA BETA de RIM. Mejoras y ...
  • WeChat para Android [Apk][Full][Gratis]
    La nueva forma de conectar! WeChat Messenger es una voz superior móvil y la aplicación de chat de texto con características de detección ...
  • Crash Bandicoot 3
    el juego pesa 167 MB Crash Bandicoot 3 - multi idiomas by Sasuke7.exe http://www.mediafire.com/download.php?cmbr67nkec6t4st   < un sol...
  • GTA San Andreas
    IMÁGENES Requerimientos Recomendados  Intel Pentium 4 o AMD Athlon XP (o superior) 384(+) MB RAM 4.7 GB HD espacio mínimo en disco Tarjeta ...
  • Street Fighter IV HD Android .Apk [Full] [Gratis]
    Street Fighter IV HD Android .Apk [Full] [Gratis] Gratis APK del juego Street Fighter IV HD Android, full descarga del juego Android de pele...
  • Tomb Raider 2 Gold
    Tomb Raider II Gold: La Máscara de Oro En el transcurso diario de sus investigaciones, Lara descubre algunas pistas referentes a una pequ...
  • BLACKBERRY MESSENGER 6.1.0.49 DISPONIBLE
    La aplicación BlackBerry Messenger ha recibido una actualización a la versión 6.1.0.49 de forma OFICIAL luego de casi 1 mes en la Zona Beta...
  • App Verizon Wireless Instating $30 Phone Upgrade Fee April 22nd
    Verizon Wireless Instating $30 Phone Upgrade Fee April 22nd Verizon Wireless is at it again with a new fee it plans to charge its customers...
  • Las mejores aplicaciones para android 2013 [Apk][Full][Gratis]
      Android es un sistema operativo basado en Linux, diseñado principalmente para móviles con pantalla táctil como teléfonos inteligentes o...

Descargar-Android.com


google android


android market apk


android market español


Descargar Android [Apk][Full][Gratis] | Las mejores aplicaciones para android descargar android para celulares | Aplicaciones Android Gratis Apk para android Gratis top apk Android Market en Español Descargar Android Marca Peru, android, aplicaciones android, market android, descargar android, mejores aplicaciones android, descargar android market, android market español, android apps, google android, android app, android market apk, android apk