[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