将UI更新为BroadcastReceiver(Update UI into BroadcastReceiver)

我是android开发的新手(对不起我的英语我是法国人)。 我想创建一个聊天应用程序。 现在我有一个基于本地数据库的列表视图。

我还有一个广播接收器,检查连接是否改变。 当连接改变并且没问题时,它会更新本地数据库。 但我希望如果应用程序正在运行该消息列表刷新。

我怎样才能做到这一点? 我的列表通过自定义游标适配器与我的本地数据库链接。

i'm new in android development(sorry for my english i'm french). I want to create a chat app. Now I have a listview based on local database.

Also I have a broadcast receiver which check if the connection changed. When the connection changed and is ok it update the local Database. But i want that if the app is running that the list of message refresh.

How can I do that? My list is linked with my local DB with a custom cursor adapter.

最满意答案

最简单的方法是使用另一个intent和广播接收器来通知应用程序的每个组件数据库已更新。 除了Android组件(意图+广播接收器),您还可以使用像Otto这样的事件总线库来简化操作。

您的活动在onCreate方法中订阅某个业务类,并在onDestroy取消订阅,因此它始终会在更改运行时收到通知。

The easiest way is to use another intent and a broadcast receiver to notify every component of your app that the database has been updated. Instead of the Android components (intent + broadcast receiver) you can also use some event bus library like Otto to make the things easier.

Your activity subscribes to some business class in the onCreate method and unsubscribes from it in the onDestroy, so it always get notified from the changes when it is running.

将UI更新为BroadcastReceiver(Update UI into BroadcastReceiver)

我是android开发的新手(对不起我的英语我是法国人)。 我想创建一个聊天应用程序。 现在我有一个基于本地数据库的列表视图。

我还有一个广播接收器,检查连接是否改变。 当连接改变并且没问题时,它会更新本地数据库。 但我希望如果应用程序正在运行该消息列表刷新。

我怎样才能做到这一点? 我的列表通过自定义游标适配器与我的本地数据库链接。

i'm new in android development(sorry for my english i'm french). I want to create a chat app. Now I have a listview based on local database.

Also I have a broadcast receiver which check if the connection changed. When the connection changed and is ok it update the local Database. But i want that if the app is running that the list of message refresh.

How can I do that? My list is linked with my local DB with a custom cursor adapter.

最满意答案

最简单的方法是使用另一个intent和广播接收器来通知应用程序的每个组件数据库已更新。 除了Android组件(意图+广播接收器),您还可以使用像Otto这样的事件总线库来简化操作。

您的活动在onCreate方法中订阅某个业务类,并在onDestroy取消订阅,因此它始终会在更改运行时收到通知。

The easiest way is to use another intent and a broadcast receiver to notify every component of your app that the database has been updated. Instead of the Android components (intent + broadcast receiver) you can also use some event bus library like Otto to make the things easier.

Your activity subscribes to some business class in the onCreate method and unsubscribes from it in the onDestroy, so it always get notified from the changes when it is running.