Android is Linux base operating system and one of one of the key principles of Linux is the separation between processes. So what happens when you want to cross the boundaries.  


In Android a service is an application component that can run long running operation without providing  UI. Services are used to do long running tasks like retrieving data from remote servers or retrieving large-size data from memory. Services -usually- run in the same process but never on the same thread as UI as executing long running tasks on UI thread would lead to blocking the UI responsiveness to user's actions and “application not responding” dialogs that will most certainly lead to bad user experience and app uninstall along the way.

A service starts in the application process as all other application components by default so what happen when a developer wants to expose  application's services so they can be used by other applications. 

There are multiple approaches to calling a remote service we can consider using broadcast&receivers and AIDL (Android Interface Definition Language).


A Broadcast receiver is an application component that listen for system events as well as application events. By definition a broadcast is transferring a message to all recipients simultaneously (one-to-all). Using a Broadcast receivers for communication with a remote service there is a couple of things needs to be taken into  consideration:

1- the maximum size of the ”Bundle” message in the Intents used to send broadcast.
If the arguments or the return value are too large to fit in the transaction buffer, then the transaction will fail and throw TransactionTooLargeException. Generally its prefered to keep message size under 1MB as it is the maximum if transaction buffer till now.

2- A broadcast is transmitted across the system and that could introduce a security threat.
Other apps can listen to broadcasts and use it for any other purpose. As a rule of thumb any sensitive data should not be broadcasted.


AIDL is allows developers to expose their services to other application by means of defining of programming interface that both the client and service agree upon in order to communicate with each other. AIDL achieves IPC by marshaling(Marshaling is the process of transforming the memory representation of an object to a data format suitable for storage or transmission. A note worth taking is that marshaling parameters is expensive) the objects. The programming interface contains the methods that other processes should use to communicate with this service. Methods accept parameters and return results in the following  data types:

1. All primitive types in the Java programming language (such as int, long, ,.....).
2. String.
3. CharSequence.
4. List (with a restriction).
5. Map (with a restriction).

The restriction on Map and List is that all elements in them must be one of the supported data types or one of the other AIDL-generated interfaces or declared Parcelables. 

The .aidl file must be copied to other applications in order for them to communicate with the service remotely so when any change is made in AIDL interface after the is service release must keep  backward compatiblity in order to avoid breaking other applications that are already using your service.

A hint mentioned in the Android API guide tells us to be aware that calls to an AIDL interface are direct function calls.  And no assumptions should be made about the thread in which the call occurs. A pure AIDL interface sends simultaneous requests to the service, which must then handle multi-threading.

AIDL vs Broadcast&Receivers

AIDL does IPC through marshaling, executes call simultaneously and require writing thread-safe code on the other hand we have got broadcast, an intent based communication with limited size message imposing security threat on sensitive information. 

Retrofit 2.0.0-beta1

September 6th 2015, 10:01 amCategory: Mobile 0 comments

Retrofit is one of the famous REST Client java libraries which we can use in android application and java desktop applications. 
We can combine Retrofit with Gson library to deal with any REST API.

Here we will show how can we use Retrofit 2.0.0 with GSON library by showing a simple example on Android to get user information and list of his repos from Github API.
At first you should setup Retrofit, Gson and GsonConverter by adding the following libraries to dependecies in gradle file:

dependencies {
 compile 'com.squareup.retrofit:retrofit:2.0.0-beta1'
 compile 'com.squareup.retrofit:converter-gson:2.0.0-beta1'
 compile ''
Then we can build the POJO(Plain Old Java Object) which we will use to cast the response from the request by using . That is a very useful online tool, it convert the josn object to Java classes which use Gson library like the follwing images: 

Create a new class GitHubUser in your code, we will use on the next lines.  

Create a GithubService Interface: 
public interface GitHubService { @GET("/users/{user}/repos") Call<List<Repo>> listRepos(@Path("user") String user); }

Now we can use Retrofit by injecting the following code in any android service which extends IntentService the following code: 
    Retrofit retrofit = new Retrofit.Builder().

    GitHubService gitHubService = retrofit.create(GitHubService.class);

    Call<GitHubUser> gitHubUserCall = gitHubService.getUserInfo("octocat");
    try {
        Response<GitHubUser> response = gitHubUserCall.execute();
        if (response.isSuccess()) {
            GitHubUser user = response.body();
            Log.d("User Email:", user.getEmail());
            Log.d("User Avatar URL:", user.getAvatarUrl());
    } catch (IOException e) {


PhoneGap is an open source framework for building cross-platform mobile apps using basic web skills like HTML5, Javascript and CSS. It is just all about wraping your app with PhoneGap to fast deploy in diffrent plateforms. I started developing applications since April'12, at the begining I was really impressed since I really used all my web skills to develop apps but after only 6 months I began to be shoked by performance and ui issues like smooth animations and more other issues.

Testing application over android environment is costly because more devices  with diffrent specs have to be tested with,
so it is costly and time consuming so indeed the best solution is to test over default Android emulator, but the first question in our minds is what we should do about emulator poor performance?

Android From A to Z

February 16th 2015, 4:05 amCategory: Mobile 0 comments

Innovative apps can be built over mobile devices in Java, Android provieds a rich framework allowing developers to do that.
Here Android fundementals concepts can be easily studied to provide android basics for developers.