简体   繁体   中英

How to handle several methods, doing heavy calculations?

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?

By looking at your question i will suggest you to use handler with java normal multi threading concept . I dont think Asyntask is 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.

There are several methods.

  1. Do calculations asynchronously. Android SDK provides Handler, IntentSevice, AsyncTask, HandlerThread to solve problems asynchronously. By the way, it is recommanded to use multi-thread solving heavy calclations.

  2. Let server do calculations. Mobile devices is not suitable for calculating, calculations consume power and affect app performance.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM