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 implement 3D / tilt mode in mapview?
Android calendar : created an event using intent , but it does not go back to my activity
how can I two way sync data between android device and webserver?
How to use SharedPreferences to save more than one values?
Android: Workaround for support.v4.app.Fragment -> Fragment classcastexception?
All EditText inside an alert Dialog are not visible
Launch Custom Dialog from Alert Dialog - NullPointer error
Realtime html 5 application polling
Java null pointer exception while using google maps in Android
Reflection for Finding Classes in Android Application
How to improve memory usage with BitmapFactory.decodebyteArray()?
Send touch screen event to foreground activity (only from APK)
How to auto-pair to another Android device over Bluetooth without prompting for a pin?
I want to download an audio from the server
Can we add our application setting menu to the android device settings menu
Simulate Multi Touch in Android Emulator

Categories

HOME
asp.net-web-api
oracle12c
porting
css3
zend-framework
youtube-data-api-v3
mysql-workbench
obfuscation
sitecore
access
spring-data-mongodb
rds
onclick
jetty
angularfire2
minecraft-forge
drop-down-menu
fhir
project-intu
resultset
ipmitool
nancy
pybossa
docx
package.json
intershop
mathprog
imessage
sse
sigma.js
nim
lilypond
jquery-ias
mongoid6
fable-f#
asymptotic-complexity
cppreference
uitapgesturerecognizer
nsurl
alm
send
deltaspike
jmockit
rselenium
sharding
html-encode
sql-delete
imagenet
reactivekit
filesystemwatcher
jvmti
chef-solo
kill
magento-1.9.3
stringtokenizer
oracle-service-bus
apollostack
clang++
dynamic-linq
xbmc
openresty
reportservice2010
rserve
bluez
spring-data-couchbase
bootstrap-tags-input
autosar
flex-monkey
refinerycms
fink
nullable
cycle2
toran-proxy
.bash-profile
visual-sourcesafe-2005
entity-framework-4.3
phpldapadmin
android-cookiemanager
uncaught-typeerror
mruby
tweenlite
angular-carousel
build-script
ora-00904
vbe
conditionaltagsupport
getopt
gwt-openlayers
sphinxql
embedded-fonts
c++builder-xe5
mbunit
cascadingdropdown
apache-whirr
oracle-enterprise-linux
jquery-address
filemerge
load-time
ie-compatibility-mode
zen
nstokenfield
dsoframer
commercial-application

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