android


Accelerometer RxJava Backpressure


Having trouble with backpressure. Using publish subject to get Sensor event on emitting, and need to save data to database on subscribe to subject in transaction.
I have been trying to use .window(100) operator so i can bulk insert whenever i get 100 sensor event's in a row but i can only get one item at .subscribe()
Don't want to drop events by using buffer operator. What is the right way to handle this?
#Override
public void onSensorChanged(SensorEvent sevent) {
Sensor sensor = sevent.sensor;
switch (sensor.getType()) {
case Sensor.TYPE_ACCELEROMETER:
sensorEventPublishSubject.onNext(sevent);
break;
}
}
sensorEventPublishSubject
.map(event ->
new AccModel(
event.values[0],
event.values[1],
event.values[2],
event.accuracy
)
)
.window(100)
.subscribe(
new Action1<Observable<AccModel>>() {
#Override
public void call(Observable<AccModel> accModelObservable) {
//insert in db
}
}
);
You have two options, depending on what you want to do with the onError event.
First off, your solution using .window is correct, it's just that it emits an Observable, and you will get one Observable every 100 events, and that Observable will, when you subscribe to it, replay those 100 events. Also, in the case of an error, it will replay the error event in sequence too (AFAIK).
If you don't care about the error event in the sequence, then there's the solution with .buffer(100), in front of which you should put onErrorReturn() or onErrorResumeNext() which you will use to transform the onError event into the onNext. That's because in case of an onError, buffer operator immediately propagates it so you lose the events in the temporary buffer (<100).

Related Links

how to get city name using latitude and longitude in android
Optimal configuration for background scan - Android / AltBeacon
FFmpeg4Android how to stop processing?
How to get Access token from Linked In android sdk?
Android mkdirs() doesn't work
Does an SQLite database offer additional security in comparison with Files in Android?
How to monetize Unity apps with Tencent Social Ads?
Call method in a running activity from a service
Go back to MainActivity from any activities with Flag
loading mp4 videos in to our app in android
how can I send the real-time database to the registered user email that created using Firebase??
Accessing Browsers sharing functionality from web page
onClicklistener is not working while thread is running
android SDK path not working for Ubuntu 16.04
Android unittest googletest
icon is not changing with custom tab layout

Categories

HOME
uml
grok
kentico
can
aws-cli
rds
mips
echo
recordrtc
pattern-matching
little-proxy
startup
mod-security
scrolltop
do-while
azure-iot-hub
entitymanager
scsi
red5
video-editing
xmonad
boost-icl
spring-async
dpdk
backpack-for-laravel
ember-cli
pchart
ckfinder
beautifier
slidetoggle
genexus-sd
constexpr
glib
memory-address
linkedhashmap
hibernate-search
jwplayer6
sharepoint-workflow
latitude-longitude
password-protection
numberpicker
escpos
preloader
lpsolve
apollostack
avcapturedevice
stylecop
servermanager
mesosphere
getchar
sonarlint-eclipse
pair-programming
truezip
arules
cup
oozie-coordinator
reshape
lsyncd
vibrate
structuremap4
delta
turbo-prolog
atan2
boomerang
toran-proxy
dllimport
dbaccess
cosine-similarity
webmatrix-3
packet-sniffers
sip-server
big-ip
wcm
insight.database
mdichild
dct
ios8-extension
buffering
renderer
koala
breakout
script#
gpars
route-provider
android-sdk-2.3
jsr286
jquery-address
node-redis
expression-blend-4
umra
cloudfiles
mtu
cac
luajava
drupal-fivestar
pos-for-.net
django-piston
escrow
wysiwym
fault-tolerance
unmanagedresources

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App