The use of open source framework can greatly reduce the difficulty of development, reduce the development cycle, and fewer bugs, software run more stable.
Xutils Introduction
Xutils contains a lot of useful Android tools.
Xutils supports large file uploads, more comprehensive HTTP request protocol support (10 predicates), more flexible ORM, more event annotations support, and is not affected by confusion ...
XUITLS Minimum compatible Android 2.2 (API Level 8)
: Https://github.com/wyouflf/xUtils
Here is a demo:
Public class mainactivity extends Activity { PrivateEditText Et_path;PrivateTextView Tv_info;@Override protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Setcontentview (R.layout.activity_main); Et_path = (EditText) Findviewbyid (R.id.et_path); Tv_info = (TextView) Findviewbyid (r.id.tv_info); } Public void Download(View view) {String path = Et_path.gettext (). toString (). Trim ();if(Textutils.isempty (path)) {Toast.maketext ( This,"Please enter the path of the download",0). Show ();return; }Else{Httputils http =NewHttputils (); HttpHandler handler = http.download (Path,"/sdcard/xxx.zip",true,//If the destination file exists, then the unfinished portion continues to download. The server does not support range when it is newly downloaded. true,//If the file name is obtained from the request return information, it is automatically renamed after the download is complete. NewRequestcallback<file> () {@Override Public void OnStart() {Tv_info.settext ("Conn ..."); }@Override Public void onloading(LongTotalLongCurrentBooleanisuploading) {Tv_info.settext (current +"/"+ total); }@Override Public void onsuccess(responseinfo<file> responseinfo) {Tv_info.settext ("Downloaded:"+ ResponseInfo.result.getPath ()); }@Override Public void onfailure(httpexception error, String msg) {Tv_info.settext (msg); } }); } }}
With a ready-made open source framework, the benefits are great!
Multi-threaded breakpoint download implementation under Android 2 leverage open source framework Xutils