在后台运行的活动 [英] Running activity in the background

查看:96
本文介绍了在后台运行的活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是想知道如果我能收集一些建设性的意见。嗯,我正在开发一个标签式的应用程序与活动组为每个标签和相关的子活动。一个活动的处理downloader-等待来自服务器的下载链接文件时,一旦接收到下载开始在后台。完成时,文件(主要是PDF)开辟了在一个通用的浏览器。这部分工作非常出色。

Just wondering if I could gather some constructive comments. Well, I am developing a tabbed application with activity group for each tab and related child activities. One of the activities handles a file downloader- waits for the download link from the server, once received download begins in the background. On completion, the file (mostly PDF) opens up in a generic viewer. This part works exceptionally well.

现在,即将应用的要求,我想该活动在后台运行。当用户在下载页面上,它显示了一个进步提供必要的信息对话框。用户,已经决定转行到其他屏幕,移动到其他屏幕。在现实中,下载活动应该在后台运行。

Now, coming to app requirement, I want the activity to run in background. When the user is in the download page, it shows a progress dialog with necessary messages. User, having decided to switch to other screens, moves to other screens. In real, the downloader activity should run in background.

一个典型的下载活动类是这样的:

A typical download activity class looks like:

 public class DownloadActivity extends Activity {
    public void onCreate(Bundle state) { //code here}
    public void onPause() {//can anything be done here?}
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
           //go back to previous screens to check other features
           TabGroupActivity parentActivity = (TabGroupActivity)getParent();
           //onBackPressed()- current activity is killed and new one is created
           parentActivity.onBackPressed();
           return true;
        }
        return super.onKeyUp(keyCode, event);
    }
 }

我想修改上述活动,以帮助它工作的背景,而用户播放变通与其他屏幕。

I want to modify the above activity to help it work background while user plays arounds with other screen.

有什么想法?

希望这不是乱了套!让我知道如果你不明白上述任何。

Hope it is not very confusing! Let me know in case you don't understand any of the above.

在此先感谢!

推荐答案

活动 不能不应该工作背景。对于Android的后台操作,你应该使用服务

Activity can't and shouldn't work in background. For background operations in Android you should use Service.

有关于Android 流程和服务的文章。

There is an article about Android processes and services.

服务没有用户界面,它应该做的所有工作,在后台。 活动可以显示当前的应用程序状态(S)的用户,即改变/由服务修改。当服务完成他的工作,也可以发送通知为例。更多详细信息,请参阅指南rel="nofollow">。

Service doesn't have UI, it should do all the job, in the background. Activity can display current application state(s) to the user, that is changed/modified by Service. When Service finish his work, it could send a Notification, for example. More details in this guide.

这篇关于在后台运行的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆