Asynchronous storage of Android cookies

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.