分享DBAdapter活动之间 [英] Share DBAdapter Between Activities

查看:161
本文介绍了分享DBAdapter活动之间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,所以在我的应用我有一个DBAdapter类,它的工作好。在主要的活动,我有一个变量 this.dbAdapter 。我想与大家分享与其他Activites这个变量,所以我不必在创建活动每一个新的DBAdapter。

Ok so in my application I have a DBAdapter class, that does its job well. In the main Activity, I have a variable this.dbAdapter. I would like to share this variable with other Activites, so I don't have to create a new DBAdapter in each Activity.

怎么会是这样做的最佳方式?我应该做的事情,比如 intent.putExtra(DbAdapter,this.dbAdapter); ?或者是有,我应该去做另一种方式?

How would be the best way of doing this? Should I do something like intent.putExtra("DbAdapter", this.dbAdapter);? Or is there another way that I should go about it?

谢谢!

推荐答案

这与Android集成的最佳解决方案是的创建内容提供商并有每个活动查询它,使用适配器,以配合您的查询结果以您的小部件。然而,你可以只用建立在每个活动新DBAdapter,确保当活动暂停,关闭所有资源度日。如果你需要在你的适配器坚持的状态,你可能做错了什么。

The solution that integrates best with Android is to create a Content Provider and have each activity query it, using an Adapter to tie your query results to your widgets. However, you can get by with just creating a new DBAdapter in each Activity, making sure to close all resources when the Activity is paused. If you need to persist state in your Adapter, you're probably doing something wrong.

这篇关于分享DBAdapter活动之间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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