Eclipse 【ADT】 源

https://dl-ssl.google.com/android/eclipse


Notice that no matter what scenario causes the activity to stop, the system always calls onPause() before calling onStop().

Although the onPause() method is called before onStop(), you should use onStop() to perform larger, more CPU intensive shut-down operations, such as writing information to a database.

the system calls onStart() both when it creates your activity and when it restarts the activity from the stopped state.

Resumed

In this state, the activity is in the foreground and the user can interact with it. (Also sometimes referred to as the “running” state.)

Paused

In this state, the activity is partially obscured by another activity—the other activity that’s in the foreground is semi-transparent or doesn’t cover the entire screen. The paused activity does not receive user input and cannot execute any code.

Stopped

In this state, the activity is completely hidden and not visible to the user; it is considered to be in the background. While stopped, the activity instance and all its state information such as member variables is retained, but it cannot execute any code.


//保证当前的版本可以执行某段代码

1
2
3
if ( Build.VERSION.SDK_INT >=Build.VERSION_CODES.HONEYCOMB ) {   

}

onCreate<—>onDestroy,执行一次;

onStart<—>onStop,循环;

onResume<—>onPause,循环;


In order for the Android system to restore the state of the views in your activity, each view must have a unique ID, supplied by the android:id attribute.


As the system begins to stop your activity, it calls onSaveInstanceState() (1) so you can specify additional state data you’d like to save in case the Activity instance must be recreated. If the activity is destroyed and the same instance must be recreated, the system passes the state data defined at (1) to both the onCreate() method (2) and the onRestoreInstanceState() method (3).

When your activity is recreated after it was previously destroyed, you can recover your saved state from the Bundle that the system passes your activity. Both the onCreate() and onRestoreInstanceState() callback methods receive the same Bundle that containes the instance state information.

Because the onCreate() method is called whether the system is creating a new instance of your activity or recreating a previous one, you must check whether the state Bundle is null before you attempt to read it. If it is null, then the system is creating a new instance of the activity, instead of restoring a previous one that was destroyed.

Instead of restoring the state during onCreate() you may choose to implement onRestoreInstanceState(), which the system calls after the onStart() method. The system calls onRestoreInstanceState() only if there is a saved state to restore, so you do not need to check whether the Bundle is null.


从.java中和从.xml中load resource

// Get a string resource from your app’s Resources

1
String hello =getResources().getString(R.string.hello_world);

// Or supply a string resource to a method that requires a string

1
2
3
TextView textView =newTextView(this);

textView.setText(R.string.hello_world);
1
2
3
4
5
6
7
<TextView

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:text="@string/hello_world" />

【Supporting different screens】

There are four generalized sizes: small, normal, large, xlarge

And four generalized densities: low (ldpi), medium (mdpi), high (hdpi), extra high (xhdpi)

Also be aware that the screens orientation (landscape or portrait) is considered a variation of screen size, so many apps should revise the layout to optimize the user experience in each orientation

Android automatically scales your layout in order to properly fit the screen. Thus, your layouts for different screen sizes don’t need to worry about the absolute size of UI elements but instead focus on the layout structure that affects the user experience (such as the size or position of important views relative to sibling views).

By default, the layout/main.xml file is used for portrait orientation.

If you want a provide a special layout for landscape, including while on large screens, then you need to use both the large and land qualifier:

MyProject/

    res/ 

            layout/main.xml                                  # default (portrait)  

            layout-land/main.xml            # landscape

            layout-large/main.xml            # large (portrait) 

            layout-large-land/main.xml       # large landscape

xhdpi: 2.0

hdpi: 1.5

mdpi: 1.0 (baseline)

ldpi: 0.75

This means that if you generate a 200x200 image for xhdpi devices, you should generate the same resource in 150x150 for hdpi, 100x100 for mdpi, and 75x75 for ldpi devices.


如果用Android SDK Manager下载了Support lib,则无论创建mini SDK version为多高的project,android-support-v4.jar都会被自动拷贝到lib下,并且关联起来。

The Android Support Library provides a JAR file with an API library that allow you to use some of the more recent Android APIs in your app while running on earlier versions of Android.

If you decide for other reasons that the minimum API level your app requires is 11 or higher, you don’t need to use the Support Library and can instead use the framework’s built in Fragment class and related APIs.


activity与其对应的layout/*.xml并不需要名字对应

而是,得在.xml中添加的元素中至少有一个@+id,这样才会让R注册这个.xml作为一个layout.


Your app’s internal storage directory is specified by your app’s package name in a special location of the Android file system.

Tip: Although apps are installed onto the internal storage by default, you can specify the android:installLocation attribute in your manifest so your app may be installed on external storage. Users appreciate this option when the APK size is very large and they have an external storage space that’s larger than the internal storage. For more information

Caution: Currently, all apps have the ability to read the external storage without a special permission. However, this will change in a future release. If your app needs to read the external storage (but not write to it), then you will need to declare the READ_EXTERNAL_STORAGE permission. To ensure that your app continues to work as expected, you should declare this permission now, before the change takes effect.

1
2
3
4
5
6
7
 <manifest ...>

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    ...

</manifest>

However, if your app uses the WRITE_EXTERNAL_STORAGE permission, then it implicitly has permission to read the external storage as well.

You don’t need any permissions to save files on the internal storage. Your application always has permission to read and write files in its internal storage directory.


Remember that getExternalFilesDir()creates a directory inside a directory that is deleted when the user uninstalls your app. If the files you’re saving should remain available after the user uninstalls your app—such as when your app is a camera and the user will want to keep the photos—you should instead use getExternalStoragePublicDirectory().

Note: When the user uninstalls your app, the Android system deletes the following:

•All files you saved on internal storage

•All files you saved on external storage using getExternalFilesDir().

However, you should manually delete all cached files created with getCacheDir() on a regular basis and also regularly delete other files you no longer need.


Just like files that you save on the device’s internal storage, Android stores your database in private disk space that’s associated application. Your data is secure, because by default this area is not accessible to other applications.


Eclispe 【Git】 plug-in:

http://download.eclipse.org/egit/updates

http://www.eclipse.org/egit/download/


MPC is included in all of the packages available from the Eclipse download page (except the Classic Package).


【subversion SVN】 eclipse plugin subeclipse source:

http://subclipse.tigris.org/update_1.0.x


【Activities组成一个Stack】

不同应用程序之间的Activities共同组成一个Stack的Task,call的过程是1.onCreate-1.onStart-1.onResume-1.onPause-2.onCreate-2.onStart-2.onResume-1.onStop-2.onPause-3.onStart-… … back的过程是3.onPause-2.onRestart-2.onStart-2.onResume-3.onStop-3.onDestory..

可见back的过程中出栈的activity是被destory掉了;默认在call的过程中不会destory掉上一个activity,但如果调用了fininsh,则在back的过程中由于此activity已经被destory了,不会出现在back链上。

假如一个Activity的manifest定义其theme是diaolog,则状态链条中会少一个onStop,只是onPause.


在layout.xml中和在.java中声明组件的意义

在layout.xml中声明的组件可以在任何地方被R.layout.id调用到;

而在.java中声明的组件是.java私有的。


如果在setContentView为layout.xml之前调用findViewById,则返回null


getCacheDir()方法用于获取/data/data//cache目录
getFilesDir()方法用于获取/data/data//files目录


【探测键盘是否呼出的一种不靠谱方法】

1
android:windowSoftInputMode="adjustResize"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
final View root = findViewById(R.id.editnotelayout);

root.getViewTreeObserver().addOnGlobalLayoutListener(

new OnGlobalLayoutListener() {

@Override

public void onGlobalLayout() {

Rect r = new Rect();

root.getWindowVisibleDisplayFrame(r);

int heightDiff = root.getRootView().getHeight() - (r.bottom - r.top);

if (heightDiff > 100) {

System.out.println("1: ....Keyboard show");

} else {

System.out.println("1: ....Keyboard hidden");

}

}
});

读书笔记-Android初学笔记的更多相关文章

  1. [ 原创 ]学习笔记-Android 学习笔记 Contacts (一)ContentResolver query 参数详解 [转载]

    此博文转载自:http://blog.csdn.net/wssiqi/article/details/8132603 1.获取联系人姓名 一个简单的例子,这个函数获取设备上所有的联系人ID和联系人NA ...

  2. android 应用笔记

    android 应用笔记 android 应用笔记 小书匠 Android 综合教程 Android常用技巧 安卓系统架构 安卓源码开发 安卓驱动 Linux内核 安卓应用开发 Java 教程 tic ...

  3. 【转】 Pro Android学习笔记(七八):服务(3):远程服务:AIDL文件

    目录(?)[-] 在AIDL中定义服务接口 根据AIDL文件自动生成接口代码 文章转载只能用于非商业性质,且不能带有虚拟货币.积分.注册等附加条件.转载须注明出处:http://blog.csdn.n ...

  4. 读书笔记--Android Gradle权威指南(下)

    前言 最近看了一本书<Android Gradle 权威指南>,收获挺多,就想着来记录一些读书笔记,方便后续查阅. 本篇内容是基于上一篇:读书笔记--Android Gradle权威指南( ...

  5. Android动画学习笔记-Android Animation

    Android动画学习笔记-Android Animation   3.0以前,android支持两种动画模式,tween animation,frame animation,在android3.0中 ...

  6. Android 学习笔记之Volley(七)实现Json数据加载和解析...

    学习内容: 1.使用Volley实现异步加载Json数据...   Volley的第二大请求就是通过发送请求异步实现Json数据信息的加载,加载Json数据有两种方式,一种是通过获取Json对象,然后 ...

  7. Android笔记——Android中数据的存储方式(三)

    Android系统集成了一个轻量级的数据库:SQLite,所以Android对数据库的支持很好,每个应用都可以方便的使用它.SQLite作为一个嵌入式的数据库引擎,专门适用于资源有限的设备上适量数据存 ...

  8. Android笔记——Android中数据的存储方式(二)

    我们在实际开发中,有的时候需要储存或者备份比较复杂的数据.这些数据的特点是,内容多.结构大,比如短信备份等.我们知道SharedPreferences和Files(文本文件)储存这种数据会非常的没有效 ...

  9. C++ STL初学笔记

    C++  STL初学笔记 更系统的版本见徐本柱的PPT set 在这儿:http://www.cnblogs.com/pdev/p/4035020.html #include <vector&g ...

随机推荐

  1. c++编译错误提示及解决

    IntelliSense: #error 指令: Please use the /MD switch for _AFXDLL builds 修改设置:工程(Project)-> 属性(Prope ...

  2. Python基本运算符

    Python基本运算符 什么是操作符? 简单的回答可以使用表达式4 + 5等于9,在这里4和5被称为操作数,+被称为操符. Python语言支持操作者有以下几种类型. 算术运算符 比较(即关系)运算符 ...

  3. 获取<img src="sdf.jpg" Big="sf.jpg">中的big的值

    原代码: <img src="sdf.jpg" Big="sf.jpg" onclick="getsrc($(this).attr(" ...

  4. AppDelegate方法中文记录

    /// 在程序启动之后,重写自定义设置的位置 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOption ...

  5. 创建为ClickOnce清单签名的.pfx格式数字证书

    ------ 第一步 创建 X.509 证书 ------makecert.exe为证书创建工具.证书创建工具生成仅用于测试目的的 X.509 证书.它创建用于数字签名的公钥和私钥对,并将其存储在证书 ...

  6. 使用BLADE构建c++工程管理

    使用BLADE构建c++工程管理 字数764 阅读2753 评论2 喜欢4 一. c++工程依赖管理 之前在百度一直使用comake2构建c++项目,十分方便.免去了手写Makefile的痛苦,很多项 ...

  7. salt stack 工具之一——远程命令

    salt stack 远程命令 salt stack是一种自动化的运维工具,可以同时对N台服务器进行配置管理.远程命令执行等操作. salt stack分为两个部分: salt-master,部署在控 ...

  8. DNX 版本升级命令

    一.稳定版本 dnvm install latest -a x86 -r clrdnvm install latest -a x86 -r coreclrdnvm install latest -a ...

  9. 15分钟学会使用Git和远程代码库

    git是个了不起但却复杂的源代码管理系统.它能支持复杂的任务,却因此经常被认为太过复杂而不适用于简单的日常工作.让我们诚实一记吧:Git是复杂的,我们不要装作它不是.但我仍然会试图教会你用(我的)基本 ...

  10. js中的全局变量和静态变量的使用, js 的调试?- 如果js出错, js引擎 就会停止, 这会 导致 后面的 html中 refer 该函数时, 会报错 函数为定义!!

    效果里面的函数, 如show, hide,slideDown等, 这些都叫 "效果"函数, 但是里面可以包含动画, 也可以 不包含动画. 动画,是指 元素 的内容 是 逐渐 显示/ ...