I am using a content observer for content://sms
. I am writing all the messages to a text file in SD card. But the onChange()
method in the content observer is called multiple times and the same message is written multiple times to the text file. How to avoid this? Also I want to know if having the content observer will slow down the phone.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
Vivek, please ensure that you unregister your content observer any time you leave the activity e.g. in
onDestroy()
method, callunregisterContentObserver()
. Hope this help ! (in my case it worked)The onChange() event is called once for each column that changes (i.e. "body" or "address") - thus the multiple calls. The easiest way to only process the data once is to store the value of the "_id" column, see if it has changed on the next iteration and then ignore.
See example here: Sms ContentObserver onChange() fires multiple times
Try this to avoid multiple execution of onChange()
You need to override deliverSelfNotifications() to return true.