2016-08-29 16:44
浏览 88


I have a mySQL database, and I created a simple android app that can display the data from the database using json. And I want to add the function wherein if a data is inserted in my database, the android app will be notified.

For example.I have two android app(App "A" and "B"). App "A" can Insert Data, and "B" can Display the data. I'm thinking of, everytime that App "A" Inserts a data, App "B" will be notified, and can refresh the current displayed data. I am thinking of refresh the list every certain time(5-10sec), but it seems to add more process time, and I think maybe refreshing it only when a data is inserted in the database would be better. Is there a way to do this? Hope that you can provide me some knowledge on how to do this. And if possible some example codes. Thank you.

图片转代码服务由CSDN问答提供 功能建议

我有一个mySQL数据库,我创建了一个简单的Android应用程序,可以使用json显示数据库中的数据。 我想添加一个功能,其中如果数据插入我的数据库,将通知Android应用程序。

例如。我有两个Android应用程序(应用程序“A”和“ B“)。 App“A”可以插入数据,“B”可以显示数据。 我想,每次App“A”插入数据时,App“B”都会收到通知,并且可以刷新当前显示的数据。 我想在每隔一定时间(5-10秒)刷新列表,但它似乎增加了更多的处理时间,我认为只有在数据库中插入数据时才会更新它。 有没有办法做到这一点? 希望你能为我提供一些如何做到这一点的知识。 如果可能的话,一些示例代码。 谢谢。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duansaoguan7955 2016-08-29 16:58

    So if your backend is built using php, this is possible. I assumed that because you've set PHP as a tag.

    Every time someone request to insert data to your php, you can insert it into MySQL and if insert went OK you could Google Cloud Messaging (GCM):

    Read documentation well, because GCM is not one-liner. It requires setup on Google console, your PHP server and Android app.

    点赞 评论

相关推荐 更多相似问题