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. LuoguP4016 负载平衡问题(费用流)

    题目描述 G 公司有 n 个沿铁路运输线环形排列的仓库,每个仓库存储的货物数量不等.如何用最少搬运量可以使 n 个仓库的库存数量相同.搬运货物时,只能在相邻的仓库之间搬运. 输入输出格式 输入格式: ...

  2. ManagementObjectSearcher 对象获取串口列表

    首先,需引用using System.Management; 可先建个枚举类,如下 #region WIN32 API /// <summary> /// 枚举win32 api /// ...

  3. Gym - 100548C The Problem Needs 3D Arrays

    Problem C.   The Problem Needs 3D Arrays Time Limit: 6000MS Memory Limit: 262144KB 64bit IO Format: ...

  4. Java表单设计器orbeon点滴

    包含表单设计器和运行展现 一个完整的应用 页面部分都是使用XML和XHTML进行服务端的组合出来的,具体逻辑有些复杂 设计器缺少一个最常用的:repeat,如果需要只能手动编写代码(参考官方文档步骤有 ...

  5. artDialog提示框、对话框

    /** * 警告 * @param {String}消息内容 */ artDialog.alert = function (content, callback) { return artDialog( ...

  6. Sql延时

    IF EXISTS(SELECT * FROM sys.procedures WHERE name='usp_wait30s')BEGIN DROP PROC usp_wait30sENDgocrea ...

  7. go pointer

    go pointer package main import "fmt" type Mutatable struct { a int b int } func (m Mutatab ...

  8. Reentrant 可重入解释

    作者:知乎用户链接:https://www.zhihu.com/question/37168009/answer/88086943来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注 ...

  9. 洛谷——P1816 忠诚

    https://www.luogu.org/problem/show?pid=1816#sub 题目描述 老管家是一个聪明能干的人.他为财主工作了整整10年,财主为了让自已账目更加清楚.要求管家每天记 ...

  10. 获取input file 选中的图片,并在一个div的img里面赋值src实现预览

    代码如下利用html5实现:几乎兼容所有主流浏览器,当然IE必须是IE 6以上 [jquery代码] $(function() { $("#file_upload").change ...