Android Multithreading in a Ui Environment
Why do we need multithreading in Android applications? Let’s say you want to do a very long operation when the user pushes a button.If you are not using another thread, it will look something like this:
1 2 3 4 5 6 7 8 9 ((Button)findViewById(R.id.Button01)).setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { int result = doLongOperation(); updateUI(result); } }); What will happen?The UI freezes. This is a really bad UI experience.