-1

so I am currently learning about Android, and I am required to make a network helper class, that will handle all my downloads, asynctasks, and network operations as a whole. I don't have idea how to do that, and just looking at a completed example wont help. Could you please tell me where I can read about such a network helper class?

4

1 回答 1

1

只需创建一个 NetworkUtils POJO 类,您可以在其中将所有 AsyncTask 声明为 NetworkUtils 的私有类,并将所有必要的方法声明为公共静态,以便可以从应用程序的任何位置轻松访问它们。通常,您希望包含一个检查有效数据连接的方法,并将任何相关方法添加到您的应用程序中,例如,将要上传/下载的文件转换为字节数组的实用程序方法。

我仍然建议(即使您说您对示例不感兴趣)您在 Github 和 Bitbucket 上浏览一些开源 Android 项目,其中一些肯定会包含这样的类。浏览您的 NetworkUtils 类应该执行的特定任务的 SO 问题,这应该让您了解如何实现各个方法。

于 2013-11-06T14:56:30.730 回答