This exception occurs due to any heavy task performed on the main thread if that performing task takes too much time.
To avoid this, we can handle it using threads or executers
Executors.newSingleThreadExecutor().submit(new Runnable() { @Override public void run() { // You can perform your task here. }});