【问题标题】:Is it possible to create an array/list of Application/Activity objects each with its own Context, each with its own LocationManager?是否可以创建一个应用程序/活动对象的数组/列表,每个对象都有自己的上下文,每个对象都有自己的 LocationManager?
【发布时间】:2013-06-30 12:40:06
【问题描述】:

请注意,我对 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 在每个中运行位置感应 - 单独且独立于每个其他。

谢谢,保重! :)

真诚地, 彼得。

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

编辑:

那么为了节省电池寿命,以下是多余的吗?:

"的以下六个场景。为简单起见,我们使用符号 {(Maintained states), Incoming state} 表示每个场景。我们 使用 (t, T0, D0) 表示传入的请求,其中 t 是时间, T0 为请求的更新时间间隔,D0 为请求的更新时间间隔 距离间隔。对于维护的状态,我们使用 (Gps, T1, D1) 表示 Gps 状态,最佳时间间隔为 T1 和 最佳距离区间为 D1。我们用 (Net, T2, D2) 来表示 最佳时间间隔为 T2 和最佳时间间隔的网络状态 距离间隔为 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

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

再次感谢!

【问题讨论】:

  • 您是否正在尝试即时启动新的应用程序实例并向它们提供您的“缓存”位置数据?
  • 我想要的本质上是从一个动态的对象中实例化它们——一个包含位置感应功能的对象,然后将每个实例存储在一个列表中以供访问。

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


【解决方案1】:

您正在尝试从本质上为您自己的目的劫持应用程序生命周期。这不是它的工作方式 - Android 应用程序声明它们希望如何运行(主要在 AndroidManifest.xml 中),并且操作系统会根据该规范行事。

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

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

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

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

【讨论】:

  • 非常感谢您的回答!所以你的意思是,他们在论文中所写的——捎带——如果不修改操作系统就不可能实现?
【解决方案2】:

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

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

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

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

这是不可能的。

【讨论】:

  • 哦,好吧,所以 LocationManager 实例是静态的,并且在 Android 设备上运行的所有应用程序之间共享?换句话说,它是在整个设备及其所有应用程序中可访问的同一个,因此它们中的每一个都将获得相同的位置而无需额外的电源?在这种情况下,我只是想理解这篇论文:deutsche-telekom-laboratories.com/~kyuhan/papers/… - 关于“piggybacking”的部分......如果它在整个设备上共享相同的 LocationManager 有什么意义? “基于多个位置的应用程序”部分。
  • @Piotr:“LocationManager 实例是静态的,并且在 Android 设备上运行的所有应用程序之间共享?” --LocationManager 是一个与核心操作系统进程对话的对象,它是实际确定位置的对象。 “所以他们每个人都将获得相同的位置,而无需额外的力量?” -- 同样,耗电量主要取决于 GPS 无线电是否打开,同时拥有多个应用程序并不会以某种方式改变这一点。
  • @Piotr:关于那篇论文,它来自 2010 年,指的是 2008 年的老式设备。此外,所提出的技术应该(并且现在主要是)在操作系统层中实现。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-01-06
  • 1970-01-01
  • 2014-08-13
  • 2020-11-06
  • 2011-03-27
  • 1970-01-01
  • 2018-07-13
相关资源
最近更新 更多