In an existing Android project I\'ve encountered the following piece of code (where I inserted the debugging litter)
ImageView img = null;
public void onCre
Use the following code, can post your code to MainThread anytime anywhere, but not depends any Context or Activity. That can prevent view.getHandler() failure or tedious onAttachedToWindow() stuffs etc.
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
//TODO
}
});