代替繁琐的finViewById

@EActivity
public class MyActivity extends Activity {
// Injects R.id.myEditText
@ViewById
EditText myEditText;
@ViewById(R.id.myTextView)
TextView textView;
}

指定需要在视图加载完成后才能执行的方法@AfterViews

@EActivity(R.layout.main)
public class MyActivity extends Activity {
@ViewById
TextView myTextView;
@AfterViews
void updateTextWithDate() {
myTextView.setText("Date: " + new Date());
}
}

注意:不要在onCreate中写任何对view相关的方法

@Extra 用于传递的Intent

@EActivity
public class MyActivity extends Activity {
@Extra("myStringExtra")
String myMessage;
@Extra("myDateExtra")
Date myDateExtraWithDefaultValue = new Date();
// The name of the extra will be "myMessage"
@Extra
String myMessage;
}

onNewIntent能够根据Intent重新注入Extra

@EActivity
public class MyActivity extends Activity {
@Extra("myStringExtra")
String myMessage;
@Override
protected void onNewIntent(Intent intent) {
setIntent(intent);
}
}

@SystemService
no more Context.getSystemService()

@EActivity
public class MyActivity extends Activity {
@SystemService
NotificationManager notificationManager;
}

@SharedPref:

定义:

@SharedPref
public interface MyPrefs {
// The field name will have default value "John"
@DefaultString("John")
String name();
// The field age will have default value 42
@DefaultInt(42)
int age();
// The field lastUpdated will have default value 0
long lastUpdated();
    @DefaultRes(R.string.defaultPrefName)
String resourceName(); @DefaultRes
String defaultPrefAge();
}

使用:

@EActivity
public class MyActivity extends Activity {
@Pref
MyPrefs_ myPrefs;
} // Simple edit
myPrefs.name().put("John"); // Batch edit
myPrefs.edit()
.name()
.put("John")
.age()
.put(42)
.apply(); // Preference clearing:
myPrefs.clear(); // Check if a value exists:
boolean nameExists = myPrefs.name().exists(); // Reading a value
long lastUpdated = myPrefs.lastUpdated().get(); // Reading a value and providing a fallback default value
long now = System.currentTimeMillis();
long lastUpdated = myPrefs.lastUpdated().getOr(now);

Andorid之Annotation框架初使用(四)的更多相关文章

  1. Andorid之Annotation框架初使用(六)

    EVENT @Click :点击事件,只能有0个或1个参数,且参数为View @Click(R.id.myButton) void myButtonWasClicked() { [...] } @Cl ...

  2. Andorid之Annotation框架初使用(七)

    Save Instance State:程序保留Activity的实例状态 , 在onSaveInstanceState(Bundle)被系统调用的时候自动保存 , onCreate(Bundle)被 ...

  3. Andorid之Annotation框架初使用(五)

    注入res文件夹的资源: @StringRes @EActivity public class MyActivity extends Activity { @StringRes(R.string.he ...

  4. Andorid之Annotation框架初使用(三)

    线程使用: @Background这个是使用了cached thread pool executor , 阻止开启过多的线程 可以为@Background指定一个id,用于随时终止线程的操作(Back ...

  5. Andorid之Annotation框架初使用(二)

    Fragment: @EActivity(R.layout.fragments) public class MyFragmentActivity extends FragmentActivity { ...

  6. Andorid之Annotation框架初使用(一)

    1. 设置Activity的布局 @EActivity(R.layout.main) public class MyActivity extends Activity {} 注: 此时在Android ...

  7. AVFoundation 框架初探究(二)

    接着第一篇总结 系列第一篇地址:AVFoundation 框架初探究(一) 在第一篇的文章中,我们总结了主要有下面几个点的知识: 1.对AVFoundation框架整体的一个认识 2.AVSpeech ...

  8. Golang 网络爬虫框架gocolly/colly 四

    Golang 网络爬虫框架gocolly/colly 四 爬虫靠演技,表演得越像浏览器,抓取数据越容易,这是我多年爬虫经验的感悟.回顾下个人的爬虫经历,共分三个阶段:第一阶段,09年左右开始接触爬虫, ...

  9. Spring框架的第四天(整合ssh框架)

    ## Spring框架的第四天 ## ---------- **课程回顾:Spring框架第三天** 1. AOP注解方式 * 编写切面类(包含通知和切入点) * 开启自动代理 2. JDBC模板技术 ...

随机推荐

  1. hbase学习(一)hbase简介

    1.hadoop生态系统 2.hbase简介 非关系型数据库知识面扩展 cassandra.hbase.mongodb.redis couchdb,文件存储数据库 Neo4j非关系型图数据库 3.hb ...

  2. 一张图解AlphaGo原理及弱点

    声明:本文转载自(微信公众号:CKDD),作者郑宇 张钧波,仅作学习收录之用,不做商业目的. 近期AlphaGo在人机围棋比赛中连胜李世石3局,体现了人工智能在围棋领域的突破,作为人工智能领域的工作者 ...

  3. Android Debug Bridge (adb) device - no permissions

      I have a problem connecting HTC Wildfire A3333 in debugging mode with my Fedora Linux 17. Adb says ...

  4. Django admin后台操作

    Django提供自动后台管理应用,简称admin. admin是一个应用,每个Web站点都需要它.admin通过让开发者可以在完成完整的UI之前验证处理数据的代码. 设置admin 打开setting ...

  5. 在C#中使用CURL

    private string args = "";          /// <summary>         /// 参数         /// </sum ...

  6. SQL必知必会 -------- SELECT、注释

    主要是看<SQL必知必会>第四版的书,而写的一些SQL笔记,红色的是方便以后查询的sql语句,工作中主要是使用mysql数据库,所以笔记也是围绕mysql而写的. 下文调试的数据表sql语 ...

  7. Python函数-闭包的概念

    一个函数和它的环境变量合在一起,就构成了一个闭包(closure).在Python中,所谓的闭包是一个包含有环境变量取值的函数对象.环境变量取值被保存在函数对象的__closure__属性中.比如下面 ...

  8. JVM的内存结构,JVM的回收机制

    内存作为系统中重要的资源,对于系统稳定运行和高效运行起到了关键的作用,Java和C之类的语言不同,不需要开发人员来分配内存和回收内存,而是由JVM来管理对象内存的分配以及对象内存的回收(又称为垃圾回收 ...

  9. debug id

    id是Eclipse的debugger自己生成的,用于告诉你哪些变量是指向同一个对象:id相同即指向同一个对象. primitive不是对象,所以就没有id. 但是如果你用primitive的wrap ...

  10. codeforces 220 C. Game on Tree

    题目链接 codeforces 220 C. Game on Tree 题解 对于 1节点一定要选的 发现对于每个节点,被覆盖切选中其节点的概率为祖先个数分之一,也就是深度分之一 代码 #includ ...