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 ...
随机推荐
- 结合使用AngularJS和Django
原地址 好吧,我承认自己很懒,时间又不够用. 翻译的几个文章都是虎头蛇尾,但我保证这次肯定不太监. 关键的单词不翻译,实在觉得翻译成汉语很别扭,括号里是参考翻译. 有问题和建议尽管提出来,我会改进完善 ...
- Json for Java API学习
首先声明:本文来个非常多网友的博客,我通过參考了他们的博客,大致的了解了一些项目中经常使用的Json in java 类和方法,以及关于json的个人理解 个人对json的一些简单理解 在近期的学习中 ...
- VS Code开发调试.NET Core
使用VS Code开发 调试.NET Core 应用程序 使用VS Code开发 调试.NET Core RC2应用程序,由于.NET Core 目前还处于预览版. 本文使用微软提供的示例进行开发 ...
- ubuntu 经常使用软件及环境
安装完系统后,更新系统 sudo apt-get update # 更新源索引 sudo apt-get dist-upgrade # 更新系统 sudo apt-get autoremove 1安装 ...
- poj - 1170 - Shopping Offers(减少国家dp)
意甲冠军:b(0 <= b <= 5)商品的种类,每个人都有一个标签c(1 <= c <= 999),有需要购买若干k(1 <= k <=5),有一个单价p(1 & ...
- Android LCD(三):Samsung LCD接口篇
关键词:android LCD控制器 Framebuffer PWM 平台信息: 内核:linux2.6/linux3.0 系统:android/android4.0 平台:samsung exy ...
- 解决:Determining IP Information for eth0 一直停留 无法进入系统
问题场景: vm centos6.4网卡之前一直没异常,可今天启动时一直卡在Determining IP Information for eth0,无法进入系统.网上说了非常多办法,大多都是不着边的说 ...
- 多线程之join方法
join方法的功能就是使异步执行的线程变成同步执行.也就是说,当调用线程实例的start方法后,这个方法会立即返回,如果在调用start方法后后需要使用一个由这个线程计算得到的值,就必须使用join方 ...
- css实现自适应屏幕高度
body,html{ margin:0px; height:100%; }
- 时间复杂度为O(nlogn)的LIS算法
时间复杂度为 n*logn的LIS算法是用一个stack维护一个最长递增子序列 如果存在 x < y 且 a[x] > a[y],那么我们可以用a[y]去替换a[x] 因为a[y]比较小 ...