Android Threads and updates on Main Thread

While working on the android app, I discovered the following error:
Skipped 55 frames!  The application may be doing too much work on its main thread.
I realized I was running heavy processing and UI updates on the same thread. A time consuming task (such as fetching data, filtering arrays) should run in its own thread and when the result is received/achieved the app should run UI update in the main thread.
For instance, in iOS we do:

DispatchQueue.main.async {
Once the data has been received from backend then we run self.tableView.reloadData() in the main thread to present this new data in the view.
Likewise in Android we should run heaving processing tasks in separate threads. We first define the update that we want to happen when we have received the result from a task. We create an instance of the Runnable class which will execute the UI update, in this case show the checkMark icon:

final Runnable checkMarkIsVisible = new Runnable(){
	public void run() { 
Then we create a separate thread for performing the task that can decide whether or not the checkmark will be displayed. Once the result is achieved, we run call the Runnable checkMarkIsVisible on the main thread.
final Handler mainHandler = new Handler(mContext.getApplicationContext().getMainLooper());

new Thread(new Runnable() {
	public void run(){
		 //Perform som task
		 if( isItemInList(myItem, myList) ){;

You will not receive the error message anymore.


A friend tipped me off after reading this post that instead of having to grab the main thread, you can also run on main thread using runOnUiThread:

new Thread(new Runnable() {
	public void run() {
		final String result = performBlockingTask();

		runOnUiThread(new Runnable() {
			public void run() {


Heroku installation

Install heroku by simply running the following in the command line (mac terminal).

brew install heroku/brew/heroku

Once the installation is complete you can login by:

heroku login

Then you can push your existing repo to heroku:

git push heroku master

If you get the following error:

fatal: 'heroku' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Then you are probably missing the link to your app in heroku. Add the Heroku Git URL  by:

git remote add heroku "HerokuURL"



with your app URL that you can find at Heroku > You App > Settings > Info.

Run push heroku command again and vola, the repo is deployed to Heroku.