简体   繁体   English

如何在我的Android应用程序中使用服务?

[英]How to use services in my android app?

I am working on an app which is almost complete. 我正在开发一个几乎完整的应用程序。 In the app there is data files that are downloaded and uploaded from and to the sftp server .I want that when user downloads or upload files the process starts in the background letting user to use the app .I am also performing different condition check (which I dont intend user to wait for).I have used downloadManager but still I want to know how services could be useful to app.Please help .Thanks 在该应用程序中,有数据文件可以从sftp服务器下载并上传到sftp服务器。我希望当用户下载或上传文件时,该过程在后台启动以允许用户使用该应用程序。我还要执行不同的条件检查(我不希望用户等待)。我已经使用了downloadManager,但我仍然想知道服务如何对应用有用。请帮助。谢谢

1) create simple service class, define it in Manifest. 1)创建简单的服务类,在清单中定义它。

2) use Async Task to perform the download 2)使用异步任务执行下载

As you are using services ;user dont have to interact with your app,as services run at background. 当您使用服务时;由于服务在后台运行,因此用户不必与您的应用进行交互。

And Async Task let you know the status of download by onPreExecute() and onPostExecute(). 异步任务让您知道onPreExecute()和onPostExecute()的下载状态。

After successful download show notification to user. 成功下载后,向用户显示通知。

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

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