I am trying to make some application in android (some kind of calculator app). In the app, on pressing the buttons a lot of conditions get checked using if-else. I am using onClickListener with the buttons, and so they are taking a slightly longer time to respond. So should I use multithreading to separate the logic from the main thread or rather use an onTouchListener with the buttons?
2 Answers
For the click event, keep using onClick, onTouch is used for tracking gestures.
It's not a good practice to do any logic operation inside the Main Thread. Leave it just for user interaction. You should consider use threading to avoid ANR (Application not responding). A good start is AsyncTask, that has it own method to do logic in a separete thread and update the UI on the Main Thread.
Please follow this link to get help with AsyncTask: https://stackoverflow.com/a/18827536/4973904
Hope that this could help you!

- 1
- 1

- 356
- 2
- 19
you should not do too much work on Main thread.The problem is not if else statements because conditional statements execute very fast but the logic you have written inside the if else blocks .may be your logic taking to much time to execute.
Solution:
if you want to perform extensive task , you should use some background thread or an alternative of this like Async task or Loaders.

- 1,855
- 3
- 19
- 34