Skip to main content

Posts

Showing posts from 2013

Android Looper and Toast from WorkerThread

Have you ever tried to launch Android Toast message from worker thread? Probably you are wondering why the heck it is giving this error- java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() In this article we are going to explore reason behind the above exception and try to understand how Looper works in Android. At the end, I am going to explain one approach to run Toast from a worker thread, but before that we need to understand how Looper works. If you already know in/out of Looper, you can skip below section and directly move to the solution part. Looper is a very basic wrapper class which attach a MessageQueue to a Thread and manage this queue. MessageQueue is a structure to sequentialize simultaneous processing requests of a Thread.  In Android, message/request processing classes like Handler uses Looper to manage their respective MessageQueue. Looper = Thread + MessageQueue Android Looper Life Cycle: As you can see in the abo

Java Reflection as Android API

Have you ever tried or wished to re-use or access source code which is part of a different Android APK ? If "Yes", then this article is for you. Well, I must agree its not a very common use case and when it comes to API in Android, we rather prefer JAR or Remote Service to expose functionalists. Java Reflection can be an alternate and useful API approach to expose functionalists from an APK or Application. Here I'm going to explain a design approach where we can define API for Android using Java Reflection. For this example, Host.apk is an Application which hosts one API method which we are going to access from another application Client.apk . Host.apk includes- HostApi.java which defines API method getMeta() . This method returns some pre-defined Text appended to calling Application's Package name. package com.pras.host; import android.content.Context; public class HostApi {      Context mContext;      public HostApi(Context context) {          this.mContext = co

"Live" Sea food for dinner....

Few days back I was attaining Team dinner with my Korean team mates and As the blog title says, I guess you guys have already imagined the kind of thrilling experience I might have. We went to a famous Korean restaurant which serves "Live" Sea creatures (Yes better to use "Creature" word, as it includes I guess almost every living things of sea- Snails, Oyster, Crabs, Squid, Lobster and so on...) and cook them in-front of you. They bring a large bowl which contains all these creatures, I guess the only spice to this is some kind of Red Chilly powder and "Water". They start the fire and put the bowl on top of it. After few minutes, one waiter comes and cuts these creatures so that they mix/cook well. I must say, the waiter is pretty skillful, she is so good in pulling/picking meats from Oyster, Snails, Squid etc. and it was so fast...simply Amazing.. As I belong from a small town in India with a proximity to a big river, I'm quite comfortable/fa

InDroid- Access to Android's Hidden API

I have started one project " InDroid " to expose and share Hidden and Internal methods and variables of Android platform which are not part of Android's Standard/Public API .  These are very powerful methods and information which would help Android Application developers to make Solutions/Apps with the power of Android's native functionalists. Try the 1st version of this Library (this includes API for few important hidden methods of Telephony, Graphics and View System) and share your feedback- http://code.google.com/p/indroid/downloads/list

Drag n Drop in Android

"Drag and Drop" is one of the most cool UI interaction technique, but at the same time it appears to be a very complex implementation approach. This was my assumption (and I believe, many of you also think on the same line) before I looked into Android's "Drag n Drop" framework and API. It makes the whole implementation pretty straight forward as long as we understand the API components and its interaction. Here I'll explain important components to implement "Drag n Drop" UI in your application. Before starting the imple mentation , we need to de cide 4 important components- Drag Source , Drop Target , Data to transfer and Dr ag Gesture . Both source and destination can be any View and they can be part of 2 different Fragments/Activities "displayed on  the same Screen". Android provides a Parcelable class ClipData to hold data that you want to transfer from Source to Destination , it can hold any kind of data- te xt, UR I etc. Once