Comments (8)
@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.
On second though, this may be a case for a call-through event method because of the return value out of onStartCommand().
from transfuse.
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.
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.
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.
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.
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.
Thanks for the clarification.
from transfuse.
Related Issues (20)
- `Parcelable` not allowed as `@Extra`? HOT 14
- @Extra injection in fragments HOT 2
- Event observers in fragments are leaked when fragment is removed from activity HOT 8
- Feature request: inject extras from intent into BroadcastReceiver HOT 5
- base class with @UIThread annotations seem to be ignored HOT 5
- exception with box types as Extras
- Using a factory defined in a library HOT 4
- some generation problems after updating to latest support library HOT 14
- Activity/Fragment lifecycle calls to super not enforced HOT 14
- hardwareAccelerated attribute doesn't seem to be included in AndroidManifest.xml HOT 1
- problem building with android-apt:1.6 HOT 7
- Fragment factories should extend common base class
- Fix custom scopes
- Finalize Plugin API
- null @Parcel @Extra throws exception HOT 7
- Provides methods with same return types ignore qualifiers
- parentActivity in @Activity
- Kotlin support HOT 1
- Android API 28+ (OREO and Above)
- Using JavaFileObject.openOutputStream is very slow
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 transfuse.