Giter Site home page Giter Site logo

Comments (5)

marukami avatar marukami commented on May 8, 2024 1

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.

marukami avatar marukami commented on May 8, 2024

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.

Rainer-Lang avatar Rainer-Lang commented on May 8, 2024

@marukami Could you point me to some samples?

from rxjava-android-samples.

Rainer-Lang avatar Rainer-Lang commented on May 8, 2024

@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.

Rainer-Lang avatar Rainer-Lang commented on May 8, 2024

@marukami I use now an IntentService and it's working fine. Thanks!

from rxjava-android-samples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.