Android给apk签名那点事
我也开始面试人了
IntentService教给我什么
IntentService
前几天学习了Service,是时候来学习一下IntentService了.
一如既往,先看下官网介绍:
IntentService is a base class for Services that handle asynchronous requests (expressed as Intents) on demand. Clients send requests through startService(Intent) calls; the service is started as needed, handles each Intent in turn using a worker thread, and stops itself when it runs out of work.
This “work queue processor” pattern is commonly used to offload tasks from an application’s main thread. The IntentService class exists to simplify this pattern and take care of the mechanics. To use it, extend IntentService and implement onHandleIntent(Intent). IntentService will receive the Intents, launch a worker thread, and stop the service as appropriate.
All requests are handled on a single worker thread – they may take as long as necessary (and will not block the application’s main loop), but only one request will be processed at a time.
简单总结一下:
service的子类,用于处理异步请求,并且在工作线程按顺序处理请求,工作完后自己停止.
使用也很简单,继承IntentService,实现onHandleIntent(Intent)方法即可.
特点:
- 与Service不同,IntentService是起线程处理任务的
- 自带队列,每个请求都会排队
- 任务完成自己会调用
stopSelf结束,无需我们操心
Service学习笔记
Service
Service,四大组件之一,是一个可以在后台执行长时间运行操作而不使用用户界面的应用组件。服务可由其他应用组件启动,而且即使用户切换到其他应用,服务仍将在后台继续运行。 此外,组件可以绑定到服务,以与之进行交互,甚至是执行进程间通信 (IPC)。 例如,服务可以处理网络事务、播放音乐,执行文件 I/O 或与内容提供程序交互,而所有这一切均可在后台进行。
但是必须要提的是,虽然说是后台,但是Service运行在主线程!
PS:Service的官方文档有中文翻译了!!真是个大好的消息!
生命周期
跟Activity类似,service也有自己的生命周期,但是简单了一些.
Service的基本使用
上面的生命周期已经提示到了,使用Service有两种方式,启动/停止,绑定/解绑,一一对应:
- startService stopService(启动)
- bindService unbindService(绑定)
- 还有一种就是即调用start,又调用bind(又启动又绑定)
这几个方式都有什么区别呢?
不急,咱慢慢来,一一解答.
Android群英传笔记
Android群英传
前言
医生写的,适合进阶,不适合初学者,在这里记录一下自己所学到的知识点.
本人是奔着自定义的相关知识点来的,所以对这方面的知识点有所侧重.
第三章
- 整个界面的控件形成一个控件树,上层控件负责下层子控件的测量与绘制,并传递事件,并且每个控件树的顶点都有一个ViewParent对象,所有交互事件都由它控制
- findViewById在控件树中已深度优先遍历来查找对应元素.
- 每个Activity都包含一个Window对象(通常是PhoneWindow),它将DecorView设为整个应用窗口的根View
- requestWindowFeature()方法一定要在调用setContentView之前才有效.
- onResume之后,系统才将DecorView添加到PhoneWindow并显示.
- MeasureSpec,一个32位的int值,高2位为测量的模式,低30位为测量的大小(位运算提高并优化效率)
- EXACTLY 精确模式, 具体值/match_parent
- AT_MOST,最大值模式—wrap_content,表示子控件不允许超过该大小
- UNSPECIFIED,想多大多大,通常用于自定义View
- View默认的onMeasure只支持Exactly,可以响应具体值和match_parent,所以自定义View如果要支持wrap_content则需要重写onMeasure
- 通过MeasureSpec.getMode和getSize方法获取测量模式与大小.
- 最终要setMeasuredDimension(width,height)完成测量
- Canvas的bitmap与canvas是紧紧联系在一起的,这过程成为装载画布
- 该bitmap存储所有绘制在Canvas上的像素信息(即canvas.drawXXX()都发生在该bitmap上)
- mTouchSlop = ViewConfiguration.getScaledTouchSlop()
第四章
- 使用viewholder提高效率
- 设置显示第几项
setSelection(int n),smoothScrollBy(distance,duration),smoothScrollByOffset(offset),smoothScrollToPosition(index) listview.setEmptyView(view)处理空数据- 弹性ListView实现方法:重写
overScrollBy(..int maxOverScrollY),重新赋值参数maxOverScrollY即可
第五章
屏幕最左上角顶点作为Android坐标系的原点
getLocationOnScreen(int location[])获取在Android坐标系中的位置
ViewGroup.MarginLayoutParams更方便
通过getLayoutParams可获取LayoutParams对象
ViewDragHelper.smoothSlideViewTo(view,x,y)
ViewCompat.postInvalidateOnAnimation(view)
第六章(todo)
- canvas.save()保存画布,canvas.restore()将我们在save之后绘制的所有图像与save之前的图像进行合并(似PS中的合并图层)
- canvas.translate(x,y)将原点(0,0)移动到(x,y)并以新的点作为原点
- canvas.saveLayer(),saveLayerAlpha()将一个图层入栈,并且后面的操作都发生在这个图层
- restore(),restoreToCount()将一个图层出栈,把图层上的图像绘制到上层Canvas上
- ColorMatrix,一个4X5的数字矩阵,处理色彩效果.
ColorMatrix.setRotate(int rgb,int value)设置色调,0,1,2分别对应RGB- 饱和度(饱和度为0时,图像就变成灰度图像了)
colorMatrix.setSaturation(float sat) - 亮度(亮度为0时,图像就全黑了)
colorMatrix.setScale(float rScale, float gScale, float bScale,float aScale) - 矩阵的乘法(将矩阵的作用效果混合,从而叠加处理效果):
postContact - 使用ColorMatrix,
paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix))接着canvas.drawxx(...,paint)
6.6 Android图像处理之图形特效处理
- 变形矩阵Matrix,一个3X3的矩阵,
|A B C|
|D E F|
|0 0 1|
初始为:
|1,0,0|
|0,1,0|
|0,0,1| - Matrix的四类变换:
- 平移 set.translate 由CF控制
- 旋转 set.rotate 由ABCD共同控制
- 缩放 set.scale 由AE控制
- 错切 set.skew 由BD控制
pre()和post()提供矩阵的前乘和后乘运算,两者不相同(因此,矩阵不满足乘法交换律)- drawBitmapMesh(P144)
6.7画笔特效处理
PoterDuffXfermode 最好关闭硬件加速
Shader着色器,渲染器,用来实现一些列的渐变,渲染效果
- BitmapShader 位图Shader
- LinearGradient 线性
- RadialGradient 光束
- SweepGradient 梯度
- ComposeShader 混合
- SurfaceView 适用于频繁更新或刷新时数据处理量比较大
lockCanvas()获取Canvas,但是需要drawColor清屏unlockCanvasAndPost(mCanvas)提交canvas的内容(最好放在finally代码块中)
第七章
- 视图动画,优点:简单,缺点:不具备交互性
- AlphaAnimation
- RotateAnimation
- TranslateAnimation
- ScaleAnimation
- AnimationSet
- 属性动画
- ObjectAnimator 单一属性
- PropertyValuesHolder 多个属性结合
- ValueAnimator
- AnimatorSet
Q&A(todo)
1 | void methodA(){ |
Q:methodB 中的最后一行是否会让object的堆内存回收掉?还是说依然要等GC?
A:要等gc的,gc的时候 会去找对象是否还有ref 如果没有的话 才清除 你=null只是清除了ref