如何在android中创建多线程? [英] How to create multi thread in android?

查看:59
本文介绍了如何在android中创建多线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 android 新手,我正在做一些可能会用到的应用程序多线程.例如,应用程序线程可能会做如下假设 2线程;

I am new to android and i was doing some application which might use multi threading. For example the application threads might do as follows assuming 2 threads;

主题 1即使整个应用程序在前台线程上运行,也应该始终运行以收听特定的短信;想象一下发送这条消息时要截获的短信是3456"到电话然后线程一将被暂停并且线程 2 将被激活:

Thread 1 Even if the overall application runs on foreground thread one should run at all times listening for specific sms; Imagine the sms to be Intercepted is "3456" when this message is sent to the phone then thread one will be paused and thread 2 will be activated:

主题 2当线程被激活时,它将使用 gps 来跟踪位置手机的,将使用 smsManager 的实例发回手机的坐标(日志,纬度),甚至可能的话谷歌地图回来到发送消息3456"的电话,然后线程一将已激活:

Thread 2 When thread to is activated then it will use gps to track the location of the phone and will use instance of smsManager to send back the coordinates(log, lat) of the phone or even if possible google map back to the phone which sent the message "3456" and then thread one will be activated:

**知道如何做到这一点吗?

**How to make this happen any idea?

推荐答案

这个问题有两个答案.

  1. 如果你想在后台长时间运行一个线程,监听事件或运行一个常规进程,那么服务是必经之路

如果您需要触发一个新线程来进行一次处理然后停止,那么请查看 AsyncTask,这是一种非常非常简单的方法,并且包括一种更新用户界面的简单方法在此过程中.

If you need to fire off a new thread to do some processing once and then stop, then look at AsyncTask which is a very, very easy way to do that, and includes a simple way to update the user interface during the process.

开发人员文档包含一个关于 Android 中的位置的优秀页面

The developer docs contain an excellent page about location in Android

以下是一些有关在您的应用中接收短信的信息

这篇关于如何在android中创建多线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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