Comments (5)
A fire and forget example would look a bit like the code below.
If you need to be able to cancel the tasks, or handle more complex flows, then I don't know of any examples. In the next week or so I should have time to create some examples. If you need something now, just experiment with using Rx in Services.
@kaushikgopal Have you done anything along these lines?
public class CountIntentService extends IntentService {
public CountIntentService() {
super("CountIntentService");
}
public CountIntentService(String name) {
super(name);
}
@Override protected void onHandleIntent(Intent intent) {
// Some long running task
Observable.timer(10, TimeUnit.SECONDS)
.flatMap(new Func1<Long, Observable<Long>>() {
@Override public Observable<Long> call(final Long aLong) {
// Some 2nd long running task
return Observable.timer(10, TimeUnit.SECONDS);
}
})
.subscribe(new Subscriber<Long>() {
@Override public void onCompleted() {
// Finished
}
@Override public void onError(final Throwable e) {
// Error
}
@Override public void onNext(final Long aLong) {
// Last unit of work finished
}
});
}
}
from rxjava-android-samples.
An Intent service will work well for any one-off task that needs to outlive an activity. If you need a longer running task or more lifecycle control, then a service would be a better choice.
One use case I can think off is file transfers. Lot's of things that can go wrong, and can take a long time to finish.
from rxjava-android-samples.
@marukami Could you point me to some samples?
from rxjava-android-samples.
@marukami Thanks. I think Service will fit for me - hopefully. :)
The "send data to server" means sending a picture to the server. This I have to do later/retry in the app automatically if something goes wrong the first time. So "fire and forget" will do it for me.
I'm very interested in every example you could provide. 👍
from rxjava-android-samples.
@marukami I use now an IntentService and it's working fine. Thanks!
from rxjava-android-samples.
Related Issues (20)
- Observables Context?? HOT 1
- Rxjava 2 with Android new architecture components HOT 2
- Exceeds Dex Limit of 64k in its current state. HOT 1
- [Question] Help Needed HOT 1
- gc overhead limit exceeded?
- Mocking framework
- memory leak
- Wrapping an Android Method that requires return value
- Code of Examples
- After value change -> execute once HOT 5
- What does RotationPersist1WorkerFragment and RotationPersist2WorkerFragment do? HOT 1
- networkObserver get Exception so the final result is onError in your example when network fail even if localObeserver has data HOT 3
- Port to RxJava 2.0 HOT 12
- RxJava2: Create an examples handing backpressure HOT 2
- takeUntil optimized cache and network method and Gson parse model HOT 2
- RxJava 1 branch HOT 1
- Have you stopped maintaining this project? HOT 2
- GUI elements must not be accessed from non-main threads HOT 1
- You are using a private api (as of support library v25 and up) HOT 1
- Retrolambda is too difficult for beginners HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rxjava-android-samples.