In my app I import gpx and kml files to display tracks and waypoints on the map. For this operation, I use about 5 methods. Everything works fine, unless I try to import several long gpx/kml tracks with exfilechoser. The screen goes black for some seconds, and logcat says: skipped frames ( > 600). How could I get these calculations of the UI? Or how could I use AsyncTask with about 5 methods? Is this possible?
How to handle several methods, doing heavy calculations?
381 views Asked by stan210 AtThere are 3 answers
On
There are several methods.
Do calculations asynchronously. Android SDK provides
Handler, IntentSevice, AsyncTask, HandlerThreadto solve problems asynchronously. By the way, it is recommanded to use multi-thread solving heavy calclations.Let server do calculations. Mobile devices is not suitable for calculating, calculations consume power and affect app performance.
On
I think you should use Service which was designed for this purpose. It is said in documentation:
A Service is an application component that can perform long-running operations in the background.
You should remember about creating new thread in service.
Caution: A service runs in the main thread of its hosting process—the service does not create its own thread and does not run in a separate process (unless you specify otherwise). This means that, if your service is going to do any CPU intensive work or blocking operations (such as MP3 playback or networking), you should create a new thread within the service to do that work.
By looking at your question i will suggest you to use
handlerwith javanormal multi threading concept. I dont thinkAsyntaskis a very good approach to do long running tasks on background.It's good have do calculation on server side it reduces the overhead on mobile site.