Android:在activity之间更新bean信息
我是 Android 开发新手。 我正在尝试管理活动之间的 GPS 位置。特别是,我创建了一个线程,从主活动开始,在几个间隔后更新 gps 位置并将新位置保存到共享 Bean 中。 现在,当我将 Bean 作为附加项传递给下一个活动时,我可以获得该 Bean 的最后一个值,但是新活动上的 Bean 不会由线程更新。我不创建新的 Bean,因此我认为 Bean 的更新将在新活动中看到。 我用代码来检索新活动中的额外内容:
ShareBean pos;
Intent intent = getIntent();
Bundle extras = getIntent().getExtras();
if (extras != null)
{
pos = (ShareBean)intent.getSerializableExtra("Location");
}
任何帮助都是值得赞赏的。 提前致谢。 西蒙娜
I'm new on Android developing.
I'm trying to manage gps location between activity. In particular I have created a thread, started with main activity, that update after a few interval the gps position and save the new position into a shared Bean.
Now, when I pass as extras the Bean to the next activity, I can get the last value of the bean but, the bean on the new activity isn't updated by the thread. I don't create a new Bean, and for this reason I think that the update of the bean would be seen on the new activity.
There is the code that I use to retrieve the extra in the new activity:
ShareBean pos;
Intent intent = getIntent();
Bundle extras = getIntent().getExtras();
if (extras != null)
{
pos = (ShareBean)intent.getSerializableExtra("Location");
}
Any help is appreciate.
Thanks in advances.
Simone
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能应该使用
LocationManager
对象来获取和访问位置更新。您可以查询最后的已知位置以进行快速更新。关键是,我要求位置经理开始监听,然后我可以随时要求快速更新。我将更新的位置信息存储在我的
ApplicationContext
对象(我在本地称为appModel
)中,该信息在对象的整个生命周期中都是持久的。我像这样使用
LocationManager
:开始监听看起来像这样:
你的位置监听器可能看起来像这样:
祝你好运!
you should probably use the
LocationManager
object to get and access Location updates. You can query it for the last known location for a quick update.The key things is, I ask the location manager to start listening and then from there I can ask for quick updates anytime. I store the updated location information in my
ApplicationContext
object (which I callappModel
locally) which is persistent throughout the life of the object.I use the
LocationManager
like this:Start listening looks like this:
You location listener could look like this:
Good luck!