简体   繁体   English

Android蜂窝网络操作

[英]Android Honeycomb network operations

I've got this problem that I just can't seem to find a way around.我有这个问题,我似乎无法找到解决办法。

I'm working on an Android app for Honeycomb tablets, and it needs to connect to the internet, download some data and then update the UI once it's done.我正在为 Honeycomb 平板电脑开发 Android 应用程序,它需要连接到互联网,下载一些数据,然后在完成后更新 UI。 The thing is, however, that I need to do this any given number of times in succession.然而,问题是我需要连续执行任意给定次数。 My problem right now is that I'm using a Runnable on a new thread with a Handler that updates the UI when the network calls have been made.我现在的问题是我在一个新线程上使用 Runnable 和一个 Handler ,当网络调用完成时更新 UI。

My big issue is that I cannot be sure that the data has actually been downloaded to the device yet.我最大的问题是我不能确定数据是否已经真正下载到设备上。 All I know is that the network calls are made, and that's it.我所知道的就是进行了网络调用,仅此而已。 I cannot be sure if anything's been downloaded.我无法确定是否下载了任何内容。

The big problem in my case lies in the fact that you cannot use the main thread for your network operations in Honeycomb.就我而言,最大的问题在于您不能在 Honeycomb 中使用主线程进行网络操作。 If I had been using the main thread,如果我一直在使用主线程,

I'd really love some help on this subject.我真的很想在这个问题上得到一些帮助。 Thanks.谢谢。

UPDATE: I'll try to explain everything a bit better:更新:我会尝试更好地解释一切:

I've created a class that makes the network calls in a separate thread, and this class also contains a few methods that return various data from those network calls.我创建了一个 class 在单独的线程中进行网络调用,这个 class 还包含一些从这些网络调用返回各种数据的方法。 However, the network calls can vary in length - depending on the user's network speed - so if I call one of the methods, ie getTitle(), I can't be sure that the network call has finished yet.但是,网络调用的长度可能会有所不同——取决于用户的网络速度——所以如果我调用其中一种方法,即 getTitle(),我不能确定网络调用是否已经完成。

I need to do something along the lines of this: '- Create new instance of the class (this beings a download in a new thread) - Make sure that the download has completed, so I can use the data from it - Update a progressbar'我需要按照以下方式做一些事情:'-创建 class 的新实例(这是在新线程中下载)-确保下载已完成,以便我可以使用其中的数据-更新进度条'

That's basically what I need to do.这基本上就是我需要做的。 Hope it helped.希望它有所帮助。 Thanks谢谢

All I know is that the network calls are made, and that's it.我所知道的就是进行了网络调用,仅此而已。 I cannot be sure if anything's been downloaded.我无法确定是否下载了任何内容。

This doesn't really make sense to me.这对我来说真的没有意义。 So you're making the network calls, are you getting a response?所以你正在拨打网络电话,你得到回应了吗? Are you storing the data?你在存储数据吗?

You're not really supposed to use the main thread for network connections, do you want the user to be completely paralyzed while these network calls are happening?您真的不应该将主线程用于网络连接,您是否希望用户在这些网络调用发生时完全瘫痪?

If you use an AsyncTask for example, the onPostExecute(Object object) gets called when your calls are done and you can daisy chain those network calls using that...例如,如果您使用AsyncTaskonPostExecute(Object object)会在您的调用完成时被调用,您可以使用它菊花链这些网络调用......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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