是否可以创建一个Application / Activity对象的数组/列表,每个对象都有自己的Context,每个对象都有自己的LocationManager?

时间:2013-06-30 12:40:06

标签: android android-activity android-service android-location

请注意,我对Android非常陌生。

我正在尝试通过尝试限制位置感应等来研究节省电池寿命的方法......为此,我想“搭载”多个基于位置的应用程序的位置感知。我想要实现的是模拟多个这样的应用程序,每个应用程序都有自己的LocationListener - 来自应用程序上下文的LocationManager,我想尝试从单个活动中生成新的应用程序,就像我实例化对象一样。 这里重要的是,我可以将大量不同的应用程序上下文存储在数组或列表中。

所以,简而言之,这是一种方法:

Vector<Application> applications = new Vector<Application>();

applications.add( new Application() );
applications.add( new Application() );

// here new Application would only be an object which extends Application

等...当然,应用程序可能是一个活动或服务...我只是不知道该怎么做,所以我可以通过每个中的LocationManager运行位置感知 - 分别独立于每个其他

谢谢并保重! :)

此致 彼得。

=============================================== ===============================

编辑:

所以以下节省电池寿命是多余的?:

“以下六种情况。为简单起见,我们使用的符号 {(维持状态),进入状态}表示每个方案。我们 用(t,T0,D0)表示传入的请求,其中t是时间, T0是请求的更新时间间隔,D0是请求的 距离间隔。对于维护状态,我们使用(Gps,T1,D1) 表示FT嵌套时间间隔为T1和Gps的Gps状态 fi nest距离间隔为D1。我们使用(Net,T2,D2)来表示 具有fi嵌套时间间隔为T2和fi嵌套的净状态 距离间隔为D2。“

• {(Gps), Gps}: The prototype checks whether the (Gps, T1, D1)
state is valid. If so, then it compares (T1, D1) to (T0, D0). If
T1 < T0 and D1 < D0, then piggybacking is enabled, and the
piggybacking time is calculated.
• {(Gps), Net}: As Net typically has coarser location information
than Gps, the operations are similar to the ({Gps},Gps) scenario,
but the comparison is between (T2, D2) and (T0, D0).
• {(Net), Net}: Similar to {(Gps), Gps} case by replacing Gps
with Net.
• {(Net), Gps}: Since Gps is typically finer than Net, the request
cannot piggyback on existing Net registrations. The new registration is passed through                 immediately.
• {(Gps, Net), Gps}: Similar to {(Gps), Gps}.
• {(Gps,Net), Net}: The prototype firstly checks the Net state,
which is similar to that of {(Net), Net}. If not possible to piggyback, then it checks the     Gps     state, which is similar to {(Gps),
Net} scenario.

伪代码:

(c) Sensing Piggybacking (SP)
Variables
StateGps: Gps registration state
StateNet: Net registration state
time: Requested location sensing frequency
dist: Requested location sensing distance
1 Received requestLocationUpdate(provider, time, dist,...)
2 Store information about provider, time, distance
3 Check validity of StateGps and StateNet
4 If provider == Gps
5 Compare StateGps to time and dist
6 If StateGps allows piggybacking
7 Delays the registration to enable piggybacking
8 End
9 Else // provider == Net
10 Compare StateNet to time and dist
11 If StateNet allows piggybacking
12 Delays the registration to enable piggybacking
13 Else
14 Compare StateGps to time and dist
15 If StateGps allows piggybacking
16 Delays the registration to enable piggybacking
17 End
18 End
19 End

如果这不是多余的,那么如何实施呢? :)

再一次,谢谢!

2 个答案:

答案 0 :(得分:0)

  

为此,我想“搭载”多个基于位置的应用程序的位置感知。

对于“搭载”的任何传统定义,这将由硬件和操作系统自动完成。

如果100个应用程序同时要求GPS修复,则硬件不会自发增长100个GPS无线电。 (最多)一个 GPS无线电,消耗一个电量,为当前请求它们的应用程序提供位置修复。

  

这里重要的是,我可以将大量不同的应用程序上下文存储在数组或列表中。

这是不可能的。

答案 1 :(得分:0)

您正在尝试的是基本上为了您自己的目的而劫持应用程序生命周期。这不是它的工作原理 - Android应用程序声明它们想要运行的方式(主要在AndroidManifest.xml中),并且操作系统根据该规范进行操作。

如果不修改操作系统,您的方法就无法实现。这是一件好事。

让我这样说吧 - 作为一名应用程序开发人员,您是否有可能实现您的解决方案?即其他一些开发人员编写了一个改变应用程序工作方式的应用程序,就像那样?你可能有升级目标(减少电池寿命),其他开发者可能不那么高贵。

我建议您阅读整个Applications Fundamentals section(不仅仅是第一页),您将对Android的运作方式有一个基本的了解。

在提供文章链接后更新:不,我说的是你所描述的方法是不可能的:)。本文的作者尝试了一种不同的方法 - 他们注册了一个新的LocationProvider他们如何完全不清楚 - 这取决于他们对句子“SP挂钩到位置感应注册函数requestLocationUpdate()。”的含义。此外,他们在G1手机上做到了这一点,这是最早的Android消费者设备之一。他们所写的内容现在可能在实施细节的背景下已经过时了。