如何使用线程和服务。 Android版 [英] How to use threads and services. Android

查看:114
本文介绍了如何使用线程和服务。 Android版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个班。 actone,acttwo和actthree。我在actone的按钮。当我点击该按钮,我希望能够在后台不同的线程上运行acttwo,而我的UI带我到actthree,我可以做我想做的事情有,而code在acttwo (acttwo这就是为什么我希望它继续在后台运行的不断执行,我会在做上传到服务器)。

I have three classes. "actone", "acttwo" and "actthree". I have a button in "actone". When I click that button, I want to be able to run "acttwo" on a different thread in the background, while my UI takes me to "actthree" and I can do whatever I want there while the code in "acttwo" keeps executing(I'll be doing uploading to a server in "acttwo" that is why I want it to keep running in the background).

if(v.getId() == R.id.button1){

//Start "acttwo" in background on another thread.

Intent i= new Intent(actone.this, actthree.class);
            startActivity(i);
}

我该怎么办呢?我用一个服务?如果是的话,那么有什么方法?怎么做?我在Android的一个新手。请帮忙。谢谢!

How do I do that? Do I use a service? If yes, then what's the procedure? How to do that? I'm a newbie at Android. Please help. Thanks!

推荐答案

您可以使用的AsyncTask 为。服务是不是真的有用(多至code)。

You can use a AsyncTask for that. Services are not really useful (much more to code).

这篇关于如何使用线程和服务。 Android版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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