-
状态保存
onSaveInstanceState(Bundle)onSaveInstanceState(Bundle, PersistableBundle)
-
状态恢复
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import android.app.Activity; | |
| import android.net.Uri; | |
| import android.os.Build; | |
| import android.support.v4.app.ActivityCompat; | |
| import android.text.TextUtils; | |
| /** | |
| * @author CMFS | |
| */ | |
| public class ActivityUtils { |
当服务端主动断开连接时,服务端向客户端发送FIN消息请求断开连接,客户端收到消息后回复ACK消息通知服务端。此时当客户端仍然有消息需要发送时,不同的网络框架处理不一样。如android-async-http会通过socket.sendUrgentData()发送一个字节的数据来判断服务端连接是否正常,如果连接正常才会继续发送;如果连接断开则重新建立连接之后再发送请求。OkHttp则不会进行连接判断,直接发送请求,如果服务端在接收请求后回复RST消息,OkHttp会重新建立连接后再发送请求。
对于服务端来说,
android-async-http会多次发送一个字节的数据,此数据对于服务端来说是没有任何作用的。OkHttp由于没有检查连接状态,在服务端主动断开连接时,会发送无效请求,对于服务端来说,就降低了请求成功率。
当使用OkHttp时可以通过设置ConnectionPool的Keep-Alive时间来解决这个问题,默认值为5min。只要配置时间短于服务端对应的时间,就可以保证由客户端主动断开连接,就不会出现无效请求的问题。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class NestableRecyclerView : RecyclerView { | |
| constructor(context: Context?) : super(context) | |
| constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) | |
| constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle) | |
| init { | |
| requestDisallowInterceptTouchEvent(true) | |
| } | |
| private var prevY: Float = 0F |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| https://stackoverflow.com/questions/200469/what-is-the-difference-between-a-process-and-a-thread | |
| Both processes and threads are independent sequences of execution. | |
| The typical difference is that threads (of the same process) run in a shared memory space, | |
| while processes run in separate memory spaces. |