Reputation: 23
Is it possible to make
@Receiver(action ={MY_ACTION], local = true)
protected void MyMethod{
myMethod()
}
into Fragment ? It works only in Activity...
Android studio get only this information : Annotations are not allowed here
Did I forget about what?
Upvotes: 0
Views: 350
Reputation: 17140
You probably already have this right but just in case, first confirm you are using AndroidAnnotations version 3.1 or later, Here is an example gradle file from the github project using the latest stable build (4.4.0):
buildscript {
repositories {
google()
jcenter()
}
dependencies {
// replace with the current version of the Android plugin
classpath "com.android.tools.build:gradle:3.0.0"
}
}
repositories {
mavenLocal()
mavenCentral()
}
apply plugin: "com.android.application"
def AAVersion = "4.4.0" // change this to your desired version, for example the latest stable: 4.4.0
dependencies {
annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
implementation "org.androidannotations:androidannotations-api:$AAVersion"
}
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 26
// If you have different applicationIds for buildTypes or productFlavors uncomment this block.
//javaCompileOptions {
// annotationProcessorOptions {
// arguments = ['resourcePackageName': "org.androidannotations.sample"]
// }
//}
}
}
Then apply @EFragment
and tidy up your @Receiver
annnotation in your fragment class,
@EFragment
public class MyFragment extends Fragment {
@Receiver(actions = "MY_ACTION", local = true)
protected void myMethod() {
// Will be called when an MY_ACTION intent is sent.
}
}
For more information/docs, and a great @EFragment
example :
https://github.com/androidannotations/androidannotations/wiki/Enhance-Fragments
hope this helps!
Upvotes: 1