Reputation: 890
I am making a calculator app in Android that is doing a lot calculation in the onClick method causing it to skip frames:
I/Choreographer﹕ Skipped 206 frames! The application may be doing too much work on its main thread.
The method looks like this:
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnZero:
//do some stuff
break; ...
}
My question is: Can I make this run faster in any way - maybe by some threads or anything else?
Upvotes: 0
Views: 980
Reputation: 88
This appears when you put too much code in the main thread and it is taking time to process so frames are being skipped because of it.
Find the solution here:
The application may be doing too much work on its main thread
Upvotes: 1
Reputation: 604
You can use a Background-Thread like AsyncTask<...,...,...> to do the calculations and then return the result to you UI. This way the calculations arent done on the MainUI-Thread but in the Background. This way your UI wont freeze and its the common way in Android to do longer activities. See http://developer.android.com/reference/android/os/AsyncTask.html for Reference
Upvotes: 3