AndroidAnnotations说明—AndroidAnnotations它是如何工作的?
AndroidAnnotations它的工作原理很easy,它使用标准java注塑加工工具,自己主动加她一个额外的步骤生成源代码编译。
源代码是什么?每个增强的类。比方每个用@EActivity注入的Activity,会自己主动生成一个以该类类名+下划线为类名的该Activity子类。
比方以下这个类:
package com.some.company; @EActivity
public class MyActivity extends Activity {
// ...
}
将会生成以下这个子类,他们在同一个包以下但处在不同的目录:
package com.some.company; public final class MyActivity_ extends MyActivity {
// ...
}
这个子类通过复写一些方法(比方onCreate())来为你的activity添加一些行为。
上面介绍的这些就是你在AndroidManifest.xml生命Acitivty时须要为你的类名后面添加一个下划线的原因:
<activity android:name=".MyListActivity_" />
启动一个使用注入的Activity:
在Android中,我们一般会通过例如以下的方式来启动一个activity:
startActivity(this, MyListActivity.class);
然而。假设使用AndroidAnnotations的话,真正被启动的activity是MyListActivity_而不是MyListActivity:
startActivity(this, MyListActivity_.class);
Intent Builder(AndroidAnnotations 2.4及以上):
我们提供了一个静态的帮助类来启动编译生成的activity:
// Starting the activity
MyListActivity_.intent(context).start(); // Building an intent from the activity
Intent intent = MyListActivity_.intent(context).get(); // You can provide flags
MyListActivity_.intent(context).flags(FLAG_ACTIVITY_CLEAR_TOP).start(); // You can even provide extras defined with @Extra in the activity
MyListActivity_.intent(context).myDateExtra(someDate).start();
在AndroidAnnotations 2.7及以上的版本号中你能够使用还有一个启动Activity的方法startActivityForResult()了 :
MyListActivity_.intent(context).startForResult();
启动一个使用注解的服务:
在Android中。我们通常通过例如以下的方式来启动一个服务:
startService(this, MyService.class);
然而,假设使用AndroidAnnotations的话,真正被启动的Service是MyService_而不是MyService:
startService(this, MyService_.class);
Intent Builder(AndroidAnnotations 2.7及以上版本号):
我们提供了一个静态的帮助类来启动生产的Service:
// Starting the service
MyService_.intent(context).start(); // Building an intent from the activity
Intent intent = MyService_.intent(context).build(); // You can provide flags
MyService_.intent(context).flags(Intent.FLAG_GRANT_READ_URI_PERMISSION).start();
AndroidAnnotations说明—AndroidAnnotations它是如何工作的?的更多相关文章
- AndroidAnnotations使用说明书—AndroidAnnotations是怎样工作的?
AndroidAnnotations的工作方式非常easy.它使用标准的java注入处理工具,自己主动加入了一个额外的编译步骤来生成源码. 源代码是什么?每个增强的类,比方每个用@EActivity注 ...
- [转载]Android相关开发网站
my: Android 开发官方文档国内镜像-踏得网: http://wear.techbrood.com/index.html 转载自: http://my.oschina.net/luforn/b ...
- Androidannotations框架
Java注解: 注解(Annotation),也叫元数据.一种代码级别的说明.它是JDK1.5及以后版本引入的一个特性,与类.接口.枚举是在同一个层次.它可以声明在包.类.字段.方法.局部变量. ...
- Android框架之AndroidAnnotations基础
一:开源网址 https://github.com/excilys/androidannotations/wiki 二:AndroidAnnotation特点 (1)依赖注入 可以注入 views, ...
- Android开源框架:AndroidAnnotations
AndroidAnnotations首页 github上的项目地址AndroidAnnotations Github. wiki:https://github.com/excilys/androida ...
- 注解框架---AndroidAnnotations
AndroidAnnotations是一个开源框架,旨在加快Android开发的效率.通过使用它开放出来的注解api,你差点儿可以使用在不论什么地方, 大大的降低了无关痛痒的代码量,让开发人员可以抽身 ...
- Android Studio 使用笔记:记录使用Gradle配置AndroidAnnotations
系统:Mac Yosemit 10.10 JDK:1.6+ Android Studio:1.2 原来看到有人用AndroidAnnotations,十分羡慕.但是Gradle并不熟悉,现找到了正确的 ...
- Android 最火高速开发框架AndroidAnnotations简单介绍
在上一篇Android 最火的高速开发框架androidannotations配置具体解释中介绍了在eclipse中配置androidannotation的步骤,如需配置请參考. 1.目标 andro ...
- Android Studio配置 AndroidAnnotations——Hi_博客 Android App 开发笔记
以前用Eclicps 用习惯了现在 想学学 用Android Studio 两天的钻研终于 在我电脑上装了一个Android Studio 并完成了AndroidAnnotations 的配置. An ...
随机推荐
- Android APP代码拨打电话、打开手机分享功能等隐式意图
Android APP拨打电话: Intent intent=new Intent(Intent.ACTION_DIAL,Uri.parse("tel:"+110)); start ...
- RGB转为Lab空间
虽然若干年前就看过了关于色彩空间的介绍,但是直到今天才自己动手写代码做这件事情.虽然网络上已经有很多现成的例子,但是一则仅仅适用于浮点型的数据,另一方面,在实现上也有一些尚可优化之处. 色彩模型除了最 ...
- Java创建、重命名、删除文件和文件夹(转)
Java的文件操作太基础,缺乏很多实用工具,比如对目录的操作,支持就非常的差了.如果你经常用Java操作文件或文件夹,你会觉得反复编写这些代码是令人沮丧的问题,而且要大量用到递归. 下面是的一个解决方 ...
- cocos2.2.3 HelloCpp TestCpp android 环境搭建 编译
cygwin make PATH->E:\cygwin\bin JAVA_HOME->C:\Program Files\Java\jdk1.8.0_05 Eclipse->Windo ...
- PowerDesigner中SQL文件、数据库表反向生成PDM
1 反向生成PDM 1) 创建一个空的PDM模型(选择相应的DBMS): 2) 选择[Database]--[Update Model from Database ...
- GitHub基本操作(转)
一.上传代码到仓库 步骤一:创建本地仓库,如下: 创建结果: 步骤二:发布自己创建的仓库,如下: 发布完显示如下: 步骤三:向自己发布仓库上传代码,如下: 首先将代码复制到本地仓库,如下: 复制完,显 ...
- poj1236(强连通缩点)
传送门:Network of Schools 题意:一些学校联接在一个计算机网络上,学校之间存在软件支援协议,每个学校都有它应支援的学校名单(A学校支援学校B,并不表示B学校一定支援学校A).当某校获 ...
- linux下查看日志基本命令
1.cat命令: 功能:1)显示整个文件. 演示样例: $ cat fileName 2)把文件串连接后传到基本输出,如将几个文件合并为一个文件或输出到屏幕. 演示样例: $ cat file1 fi ...
- Note for video Machine Learning and Data Mining——Linear Model
Here is the note for lecture three. the linear model Linear model is a basic and important model in ...
- 在IIS上发布一个WebService,再发布一个网站调用这个WebService(实例)
首先描述一下先决条件:IIS可用,VS2005可用. 好,现在开始: 首先写一个WebService并把它发布到IIS上: 在IIS上的默认网站下新建一个“虚拟目录”,取名为“webservice1” ...