Skip to main content

Posts

Showing posts with the label Android

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...

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 ...