0

请注意,我对 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

等等......当然,应用程序可以是一个活动或服务......我只是不知道该怎么做,所以我可以通过每个位置管理器运行位置感应 - 单独且彼此独立。

谢谢并保重!:)

真诚的,彼得。

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

编辑:

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

"下面的六个场景。为简单起见,我们使用 {(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

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

再次感谢!

4

2 回答 2

0

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

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

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

我建议您阅读整个应用程序基础部分(不仅仅是第一页),您将对 Android 的工作原理有一个基本的了解。

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

于 2013-06-30T12:53:44.300 回答
0

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

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

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

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

这是不可能的。

于 2013-06-30T12:48:36.063 回答