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是怎样工作的?的更多相关文章

  1. AndroidAnnotations说明—AndroidAnnotations它是如何工作的?

    AndroidAnnotations它的工作原理很easy,它使用标准java注塑加工工具,自己主动加她一个额外的步骤生成源代码编译.         源代码是什么?每个增强的类.比方每个用@EAct ...

  2. [转载]Android相关开发网站

    my: Android 开发官方文档国内镜像-踏得网: http://wear.techbrood.com/index.html 转载自: http://my.oschina.net/luforn/b ...

  3. Androidannotations框架

    Java注解:    注解(Annotation),也叫元数据.一种代码级别的说明.它是JDK1.5及以后版本引入的一个特性,与类.接口.枚举是在同一个层次.它可以声明在包.类.字段.方法.局部变量. ...

  4. Android框架之AndroidAnnotations基础

    一:开源网址 https://github.com/excilys/androidannotations/wiki 二:AndroidAnnotation特点 (1)依赖注入 可以注入 views, ...

  5. Android开源框架:AndroidAnnotations

    AndroidAnnotations首页 github上的项目地址AndroidAnnotations Github. wiki:https://github.com/excilys/androida ...

  6. 注解框架---AndroidAnnotations

    AndroidAnnotations是一个开源框架,旨在加快Android开发的效率.通过使用它开放出来的注解api,你差点儿可以使用在不论什么地方, 大大的降低了无关痛痒的代码量,让开发人员可以抽身 ...

  7. Android Studio 使用笔记:记录使用Gradle配置AndroidAnnotations

    系统:Mac Yosemit 10.10 JDK:1.6+ Android Studio:1.2 原来看到有人用AndroidAnnotations,十分羡慕.但是Gradle并不熟悉,现找到了正确的 ...

  8. Android 最火高速开发框架AndroidAnnotations简单介绍

    在上一篇Android 最火的高速开发框架androidannotations配置具体解释中介绍了在eclipse中配置androidannotation的步骤,如需配置请參考. 1.目标 andro ...

  9. Android Studio配置 AndroidAnnotations——Hi_博客 Android App 开发笔记

    以前用Eclicps 用习惯了现在 想学学 用Android Studio 两天的钻研终于 在我电脑上装了一个Android Studio 并完成了AndroidAnnotations 的配置. An ...

随机推荐

  1. php开启openssl扩展

    windows下开启方法: 1: 首先检查php.ini中:extension=php_openssl.dll是否存在, 如果存在的话去掉前面的注释符‘:’, 如果不存在这行,那么添加extensio ...

  2. CCNP路由实验之十五 NAT(网络地址转换)

     CCNP路由实验之十五 NAT(网络地址转换) 众所周知,要让自己的电脑连上Internet,必须要到运营商(ISP)申请一个上网账号,依据此账号申请自己的宽频业务(拨号上网.商业固定IP等等) ...

  3. erlang虚拟机代码运行原理

    erlang是开源的,非常多人都研究过源码.可是.从erlang代码到c代码.这是个不小的跨度.并且代码也比較复杂. 所以这里,我利用一些时间,整理下erlang代码的运行过程.从erlang代码编译 ...

  4. js21---单体(单例)模式

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...

  5. linux host主机名配置

    1.查看主机名 #hostname 2.查看ip #ifconfig 2.添加主机名配置 #vi /etc/hosts 新增一行 172.23.26.195 vhost145.idmp.safe

  6. 利用日志使管理Linux更轻松

    利用日志使管理Linux更轻松 操作系统的日志主要具有审计与监测的功能,通过对日志信息的分析,可以检查错误发生的原因,监测追踪入侵者及受到攻击时留下的痕迹,甚至还能实时的进行系统状态的监控.有效利用日 ...

  7. error: function declaration isn’t a prototype [-Werror=strict-prototypes]

    "warning: function declaration isn't a prototype" was caused by the function like that:   ...

  8. Centos下Elasticsearch安装详细教程

    Centos下Elasticsearch安装详细教程 1.Elasticsearch简介 ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于 ...

  9. 【C语言】编写函数实现库函数atoi,把字符串转换成整形

    //编写函数实现库函数atoi.把字符串转换成整形 #include <stdio.h> #include <string.h> int my_atoi(const char ...

  10. JQuery的index()函数

    1.index(),这里的索引从0开始计数. jQueryObject.index( [ object ] ):1.1 如果没有指定参数object,则返回当前元素在其所有同辈元素中的索引位置.1.2 ...