【发布时间】:2014-08-06 07:53:31
【问题描述】:
我有我的应用程序,它从服务器下载和上传数据(我的 WebApp 是用 Java 编写的,因此使用 SOAP 网络服务在我的 Android 应用程序和 Java Web 应用程序之间进行通信)。
到目前为止我一直在使用
AsyncTask
用于调用 WebServices 下载/上传数据。
到目前为止,下载的数据量很少。 但是当我从服务器下载大量数据时,应用程序崩溃了。
参考 android ref doc。
AsyncTasks should ideally be used for short operations (a few seconds at the most.) If you need to keep threads running for long periods of time, it is highly recommended you use the various APIs provided by the java.util.concurrent pacakge such as Executor, ThreadPoolExecutor and FutureTask.
所以我认为这是 AsyncTask 用于更长时间间隔的问题。
但我无法弄清楚如何使用其他线程技术调用 Web 服务,例如:Thread Pool Executor,Future Task 或 Executor
下面是我的 LogCat:
嘿,现在还有一个问题。我已将IntentService 用于那些长期运行的网络操作(下载)。现在由于我的数据在下载时足够大。因此,如果在下载过程中互联网连接丢失,那么我必须停止我认为可以使用的 IntentService。
stopService(new Intent(MainActivity.this, IntentServiceClass .class));
调用,
onDestroy()
服务。但是写的代码,
onHandleIntent(Intent intent)
将继续执行。 (这不应该发生)。
【问题讨论】:
-
你能把logcat的错误贴出来
-
您是否考虑过使用 Android Service 进行这些冗长的操作?
-
@Fildor:我可以在Service上进行网络操作吗?因为它给了我
android.os.NetworkOnMainThreadException
标签: java android multithreading web-services android-asynctask