Andorid之Annotation框架初使用(一)
来源:互联网 发布:西安聚赢网络 编辑:程序博客网 时间:2024/06/07 03:17
1. 设置Activity的布局
@EActivity(R.layout.main)public class MyActivity extends Activity {}
注: 此时在AndroidManifest.xml 注册Activity需要: <activity android:name="MyActivity_" />
2. 设置及使用Application
设置:在AndroidManifest.xml也需要配置<application android:name="MyApplicaton_" />
@EApplicationpublic class MyApplication extends Application {}
使用:
@EActivitypublic class MyActivity extends Activity { @App MyApplication application;}
或者:
@EBeanpublic class MyBean { @App MyApplication application;}
3. 普通类
@EBeanpublic class MyClass {}
注:这个普通只能有一个构造函数,这个构造函数要不是没有参数,或者只有一个Context的参数
使用: @Bean的标签每次都会创建一个实例,所以不能继承一个使用@EBean的类
@EBeanpublic class MyOtherClass { @Bean MyClass myClass;}
声明接口的同时也实例化:
@EActivitypublic class MyActivity extends Activity { /* A MyImplementation instance will be injected. * MyImplementation 必须使用标签 @EBean and 实现 MyInterface. */ @Bean(MyImplementation.class) MyInterface myInterface;}
在普通类中引入它所在的Activity或者Service的Context
@EBeanpublic class MyClass { @RootContext Context context; // Only injected if the root context is an activity,else is null @RootContext Activity activity; // Only injected if the root context is a service,else is null @RootContext Service service; // Only injected if the root context is an instance of MyActivity,else is null @RootContext MyActivity myActivity;}
使用标签@AfterViewInject, 会在所有依赖注入完成后才执行。
@EBeanpublic class MyClass { @SystemService NotificationManager notificationManager; @Bean MyOtherClass dependency; public MyClass() { // notificationManager and dependency are null } @AfterInject public void doSomethingAfterInjection() { // notificationManager and dependency 已经设置完成 }}
注意,拥有父子关系的@AfterInject的方法名字不能相同
单例的普通类:
@EBean(scope = Scope.Singleton)public class MySingleton {}
注意: 在单例的普通类如果需要使用context,请使用ApplicationContext。也不要在这里注入view或者是view的事件
- Andorid之Annotation框架初使用(一)
- Andorid之Annotation框架初使用01
- JAVA之Annotation (一)
- Andorid之网络通信框架Volley使用和总结
- Andorid之网络通信框架Volley使用和总结
- Andorid 基础知识(一)
- Java Annotation详解(一): 理解和使用Annotation
- java annotation (注解)之我见(一)
- mybatis之annotation(一)
- Annotation 使用笔记(一)
- 【Andorid开发框架学习】之Volley入门
- Andorid框架
- Andorid中的AIDL(一)
- andorid jni入门教程一之helloworld
- andorid jni入门教程一之helloworld
- andorid jni入门教程一之helloworld
- andorid jni入门教程一之helloworld
- andorid jni入门教程一之helloworld
- JAVA String.format 方法使用介绍
- 获得网站在百度关键字搜索的排名
- 在 Adobe AIR 中为不同屏幕尺寸的多种设备提供支持
- 数据挖掘:同义词的那些事
- JNI 中文字符串转换乱码的处理
- Andorid之Annotation框架初使用(一)
- linux boa服务器
- Java创建线程数目问题
- android 屏蔽home键
- 【COCOS2DX-IOS-游戏开发之二一】之 最热血的RPG+RTS塔防游戏Flesh&Blood-Attack on Orc上线了
- 在 ubuntu下配置时区的方法
- 处理文本文件命令sed
- Eclipse插件开发如何应用另一个项目作为插件
- Android动画效果——X、Y轴抖动