GithubHelp home page GithubHelp logo

Comments (8)

johncarl81 avatar johncarl81 commented on May 18, 2024

@curioustechizen, great catch.

So, what do you say we remove the Service mapping of @OnStart (to support the depreciation) and introduce a new @OnStartCommand annotation and related Service mapping? I suppose we could map the @OnStart to the onStartCommand() method instead of removing it. Thoughts?

from transfuse.

johncarl81 avatar johncarl81 commented on May 18, 2024

On second though, this may be a case for a call-through event method because of the return value out of onStartCommand().

from transfuse.

curioustechizen avatar curioustechizen commented on May 18, 2024

I had forgotten about the return value of onStartCommand() when I originally opened this issue! Well, I think this is definitely a case for call-through event. Something like ServiceOnStartCommand. While you're at it, you might as well add binding support :-) (or maybe that qualifies as an advanced use-case where the developer should sub-class Service anyway?)

from transfuse.

johncarl81 avatar johncarl81 commented on May 18, 2024

Ok, I'll add ServiceOnStartCommand shortly.

YES, automatic binding (on injection?) would be awesome. It may be tricky to get right though, needs some thought.

from transfuse.

curioustechizen avatar curioustechizen commented on May 18, 2024

Just to clarify: The idiom for creating a started Service is as follows:

    class MyService extends Service{
    @Override
    public IBinder onBind(Intent intent){
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId){
        //Do Something
    }

    @Override
    public void onDestroy(){
        //Do Some cleanup
    }

}

In other words, since onBind() is declared as abstract in Service, you must implement it in your service and return null for a started service. Is this how the code generated by transfuse would look like?

I will think about bound services in greater detail and open a new feature request if I find it feasible.

from transfuse.

johncarl81 avatar johncarl81 commented on May 18, 2024

Yes, that is what the code generated by Transfuse would look like.
This:

@Service
@RegisterListener
public class Example implements ServiceOnStartCommand{

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        return return android.app.Service.START_STICKY;
    }

    @OnDestroy
    public void cleanup(){
        //Do some cleanup
    }
}

triggers Transfuse to generate this:

@Generated(value = "org.androidtransfuse.TransfuseAnnotationProcessor", date = "10/4/12 7:45 AM")
public class ExampleService extends Service implements ContextScopeHolder
{

    private Example example_0;
    private Scope scope_10 = new ConcurrentDoubleLockingScope();

    public void onCreate() {
        super.onCreate();
        example_0 = new Example();
    }

    public void onDestroy() {
        super.onDestroy();
        example_0 .cleanup();
    }

    public IBinder onBind(Intent intent) {
        return null;
    }

    public Scope getScope() {
        return scope_10;
    }
}

from transfuse.

johncarl81 avatar johncarl81 commented on May 18, 2024

Food for thought, in the roboject project they bind Services through injection: https://github.com/akquinet/roboject/blob/master/roboject-tutorial/src/main/java/de/akquinet/android/roboject/tutorial/activities/RobojectAdderActivity.java

from transfuse.

curioustechizen avatar curioustechizen commented on May 18, 2024

Thanks for the clarification.

from transfuse.

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.