App Dies On Startup
Solution 1:
The first thread sets initialStationsRead to true when it's done, so the second thread can pick up after that.
Busy loops are evil incarnate. If I had holy water handy, you'd be rather wet right now. :-)
(that also implies that I have really good holy-water throwing aim over long distances, which probably isn't the case)
Java has plenty of options for thread synchronization, and has had them for a decade-plus, from the low-level wait() and notify() on Object to the java.util.concurrent constructs like Semaphore. Pick one and use it, getting rid of the busy loop.
Or, follow Jan-Henk's advice and do the work serially on the same thread, based on a flag.
Any idea though why this happens on his device and not on mine or devices of other people i know?
Well, for starters, the One S is dual-core, and so your threads may actually be running at the same time (one per core). Threading problems will be more likely to surface in multi-core environments.
Also, Angelo's answer -- posted while I was writing this -- is worth noting.
Solution 2:
I don't know if that helps but keep in mind that after HoneyComb (Android 3.0) and before Donut (Android 1.6) only one AsyncTask can run simultaneously, since AsyncTask use a thread pool pattern and the default thread pool size on these versions is 1. If you want the AsyncTasks you are using to run simulteneously in these versions of Android, you can use this code executeOnExecutor(Executor, Params...) using the flag THREAD_POOL_EXECUTOR. See this answer of this previous post for more information. Seeing that the user that has an HTC One S device wich runs Android 4.0, maybe this is the source of your problem.
Post a Comment for "App Dies On Startup"