org.androidannotations.annotations.ServiceAction Maven / Gradle / Ivy
Show all versions of androidannotations-api Show documentation
/**
* Copyright (C) 2010-2016 eBusiness Information, Excilys Group
* Copyright (C) 2016-2020 the AndroidAnnotations project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed To in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.androidannotations.annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
*
* Should be used on a method that must respond to a specific action in an
* {@link EIntentService} annotated class. The method name will be used as
* action name unless the {@link #value()} field is set.
*
*
* The method signature (ie with attributes) will be a part of the IntentBuilder
* generated for the {@link EIntentService}.
*
*
* The method could contain any type or parameters.
*
*
* The class MAY contain several {@link ServiceAction} annotated methods.
*
*
*
* Example :
*
*
* @EActivity(R.layout.main)
* public class MyActivity extends Activity {
*
* public void launchAction() {
* // Note the use of generated class instead of original one
* MyIntentService_.intent(this)
* .<b>myAction</b>("test", 10L)
* .start();
* }
*
* }
*
* @EIntentService
* public class MyIntentService extends IntentService {
*
* @ServiceAction
* void mySimpleAction() {
* // ...
* }
*
* @ServiceAction
* void <b>myAction</b>(String valueString, long valueLong) {
* // ...
* }
*
* @Override
* protected void onHandleIntent(Intent intent) {
* // empty, will be overridden in generated subclass
* }
* }
*
*
*
*
*
* Note: Since
* {@link android.app.IntentService#onHandleIntent(android.content.Intent)
* IntentService#onHandleIntent} is abstract, you have to add an empty
* implementation. For convenience, we provide the
* {@link org.androidannotations.api.support.app.AbstractIntentService
* AbstractIntentService} class, which implements that method, so you do not
* have to do in your actual class if you derive it.
*
*
* Use on any native, {@link android.os.Parcelable Parcelable} or
* {@link java.io.Serializable Serializable} field in an {@link EService}
* annotated class to bind it with Android's arguments. If
* Parceler is on the classpath, extras
* annotated with @Parcel, or collections supported by Parceler will be
* automatically marshaled using a {@link android.os.Parcelable Parcelable}
* through the Parcels utility class.
*
*
* @see EIntentService
* @see org.androidannotations.api.support.app.AbstractIntentService
* AbstractIntentService
*/
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.METHOD)
public @interface ServiceAction {
/**
* Define the action's name. If this field isn't set the annotated method name
* will be used.
*
* @return the name of the action
*/
String value() default "";
}