Android cookies are saved to the database asynchronously.
CookieSyncManager inherits WebSyncManager,
Is responsible for cookie from memory to persistent Storage
Cookie synchronization can be divided into automatic synchronization and forced synchronization.
1. automatic synchronization
Automatic synchronization
Is to synchronize every five minutes, is to enable a thread to take charge of the ram
Database Synchronization. This thread maintains the message queue. When the thread starts, a message with the delay time of SYNC_LATER_INTERVAL (5 min) is generated.
Message msg =
MHandler. obtainMessage (SYNC_MESSAGE );
MHandler. sendMessageDelayed (msg, SYNC_LATER_INTERVAL );
Each time this message is processed, another message with a delay of 5 minutes will be added.
2. Force Synchronization
Force synchronous call of the sync () Interface
Public void sync (){
If (DebugFlags. WEB_SYNC_MANAGER ){
Log. v (LOGTAG, "*** WebSyncManager sync ***");
}
If (mhandler = NULL ){
Return;
}
Mhandler. removemessages (sync_message );
Message MSG =
Mhandler. obtainmessage (sync_message );
Mhandler. sendmessagedelayed (MSG,
Sync_now_interval );
}
The Sync method triggers a message with a delay value of 100 milliseconds.
In either case, the cookie is saved through the handler of another thread. The persistence operation is performed only when the message is logined.
Asynchronous implementation.