Posts

Actionbar implementation in earlier Android versions

  The ActionBar was introduced in Android 3.0 (API 11) and enable us to develop applications with a more fluid navigation using Fragments. Ever since, we are using the Action Bar in pretty much every application. The question is, how to be able to implement the Action bar in earlier < 3.0 API’s ? The support library which enables us to use Fragments for devices with API<3 is great and does the work just like we want and need. but what about action bar support? it’s not out of the box even in the support library. the excepted method of implementing Action bar for those earlier versions is actionbarsherlock(or ABS) just to keep things short. The ABS is an open-source expansion of the Android support library and it enables us to write application without having to make a implicit adjustment to out activities in order to support Action bars. The usage is simple: 1. download the project from the ABS website at : http://actionbarsherlock.com/ 2. inside the archive you’ll fi...

Utilizing Http response cache

     A typical mobile application will probably consume some resources from a web server using http requests. This repeated task has some drawbacks: Bandwidth has a cost, polling the same data over and over again results in a waste of user’s quota. the responsiveness and user experience is compromised once the user keeps waiting for data. If the requested data hasn’t changed on the server, then there’s no reason for us to fetch it. Of course, local caching of data is a must, but we also need to be able to refresh the data if it has changed on the server. A simple solution which comes out of the box for API 4+ is http response caching. Http response caching is a mechanism which enables us as developers to save a footprint of the response utilizing the abilities of the Http protocol. Basically, is holds a simple cache of the response which can be defined and enabled in code, and it prevents from fetching unchanged data from the server which was already fetched a...

Design Patterns in Android

       As Android developers or developers in general, we encounter the Design Patterns paradigms pretty much in every job. Most of us as I roughly assume – go over some of the more common design patterns as an integral part in preparing for a job interview.      It is common to assume that software developers should be familiar with what design patterns are and should be able to fire couple of them and explain their usage in modern software architecture. the common patterns that you’ll probably be asked to explain are Singleton, Factory, Strategy and maybe some more exotic ones.      So the question asked, is how do classical Design patterns come handy when planning the  architecture of an android app?      The answer to this somewhat bizarre question can be divided into two mini answers : The platform which we are developing for is not important. In other words, the fact that we are dealin...

ORM for android

     ORM – Object relational mapping has been around for quite some time now. Basically it’s a piece of software (regardless of targeted platform), which simplifies the connection between objects (as in OOP) and data in database (mostly used is tables based relational database), and it exists in order to help simplify bridging the gap between the two in our development process.     Microsoft's Entity framework is a great example for a robust easy to use framework which allows creating and querying the database from an object’s point of view with classic object oriented programming paradigms while maintaining all DB construction’s needs such as relationships between objects (tables) such as one to many or many to many including all the indexing, optimization etc..      In android, we have SQLite as a database platform, from simple to advanced application, it’s likely to assume that we’ll need some relational database to store and r...

How to update UI from a different thread

     Google has set it’s tone on some tough guidelines for developing android apps, basically there aren’t any strict rules but one very easy to misunderstand. there is a single Thread which is called the “main” thread, or “UI thread” on some places. this is the thread which is in charge on the views and interaction with the users gestures. based on the guidelines of any mobile platform at the moment, all the work that shouldn’t be done on the main thread should be done on background thread. this can be achieved in many ways, you can use AsyncTask, Or A Handler, Or a simple thread with an implementation of the   run() method within the declaration of the runnable. ok, so if I’m pulling some server data, or performing long calculations, pulling stuff from or to the Sqlite database I’ll probably use an AsyncTask. but let’s say for instance that I want to simply update the UI once every couple of seconds (update a TextView or an ImageView’s content etc..),...

How to maintain global application state

       In Android application, it’s sometimes important to keep a global application state. by global application state I mean to be able to have an entry point to the application which gives us a starter place to do stuff before the application starts. this is important in many aspects, for example, the application can start from different entry points, such as the launcher, a notification, or a service, or even by responding to a certain broadcast.     There are many approaches to achieve this goal, one of them which a prefer is the Application Class, once extending the application class, we are able to load resources, setting different contexts , or even starting a certain service before the first activity starts, this is done simply by overriding the onCreate() method. Example: public class MyApplication extends Application { boolean hasAgreed; @Override public void onCreate() { // TODO Auto-generated method stub ...

Installing the development environment for android is now easier then ever

  Developing for android can a complicated task. Some developers including myself had a hard time starting with the development due to a somewhat complicated process which should be done prior to development – Installing the development enjoinment. how we used to do it: Download the SDK Download the Eclipse Download the ADT – (Android development tools) Download the plugin for eclipse (by using https://dl.google.com/ …) now it’s easier: go to https://developer.android.com/sdk/index.html , download the package and it will include all of the above. this is probably perfect for starting to develop for the Android without having to deal with the messy installation process.