[Android] Volley source code analysis (5) Q & A, androidvolley

Source: Internet
Author: User

[Android] Volley source code analysis (5) Q & A, androidvolley

The Volley source code analysis series has been around for a while, and many readers have left me messages in private, and some problems have been thrown out at the same time. For some simple questions, we jumped over and received the question raised by @ smali in the past two days. I have to give a thumbs up on how delicate the viewer looks at the source code. I will ask this question for your consideration.

Q: When writing the file header data, why not write the Int directly but shift the data?

Let's take a look at the corresponding source code:

writeInt(os, CACHE_MAGIC);static void writeInt(OutputStream os, int n) throws IOException {        os.write((n >> 0) & 0xff);        os.write((n >> 8) & 0xff);        os.write((n >> 16) & 0xff);        os.write((n >> 24) & 0xff);}

First, we know why the write (Int) method provided by the Output stream needs to be shifted?

A: We know that, for A stream, the data that it can directly manipulate is A byte. The root cause of this problem is the misunderstanding of write (Int) provided by OutputStream. In fact, for OutputStream, when you pass in an int, it will cut off the Int and get the low-end bytes of data into the stream. That is to say, data on the 0xffffff00 bits will be lost. Therefore, data can only be written in shift mode, or you have calculated four byte arrays and then written to your stream.


Thx ~



How does android use volley in listview?

Attach images? Use it in getView of the adapter.
@ Override public View getView (int position, View convertView, ViewGroup parent) {ViewHolder viewHolder = null; if (convertView = null) {convertView = LayoutInflater. from (mContext ). inflate (R. layout. volley_list_item, null); viewHolder = new ViewHolder (); viewHolder. mTextView = (TextView) convertView. findViewById (R. id. TV _tips); viewHolder. mImageView = (NetworkImageView) convertView. findViewById (R. id. iv_image); convertView. setTag (viewHolder);} else {viewHolder = (ViewHolder) convertView. getTag () ;}string url = ""; url = urlArrays [position % urlArrays. length]; viewHolder. mTextView. setText (position + "|" + urlArrays. length); viewHolder. mImageView. setImageUrl (url, ImageCacheManager. getInstance (). getImageLoader (); return convertView ;}
 
Can the Volley framework of Android be used for communication with WebService?

No, you also know that velloy uses the http protocol. Webservice uses soap. Two different communication mechanisms
 

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.