第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

在service中調(diào)用子線程報(bào)異常


??? @Override
??? public int onStartCommand(Intent intent, int flags, int startId) {
?? ??? ?//實(shí)例化 MyHandler類
?? ??? ?myHandler=new MyHandler();
??????? if(ACTION_START.equals(intent.getAction())){?? ??? ?
?????? ??? ?FileInfo fileInfo=(FileInfo)intent.getSerializableExtra("fileInfo");
?????? ??? ?//啟動(dòng)初始化線程
?????? ??? ?Log.d("huefew","正常");
?????? ??? ?new InitThread(fileInfo).start();
??????? }else if(ACTION_STOP.equals(intent.getAction())){
?????? ??? ?FileInfo fileInfo=(FileInfo)intent.getSerializableExtra("fileInfo");
?????? ??? ?if(mTask!=null){
?????? ??? ??? ?mTask.isPause=true;
?????? ??? ?}
??????? }
?? ??? ?return super.onStartCommand(intent, flags, startId);
??? }
??? @Override
??? public void onDestroy() {
?? ??? ?// TODO Auto-generated method stub
?? ??? ?super.onDestroy();
??? }?? ?
???
??? /*
???? * 初始化子線程
???? */
??? class InitThread extends Thread{
?? ??? ?private FileInfo mFileInfo=null;
?? ??? ?public InitThread(FileInfo mfileInfo){
?? ??? ???? this.mFileInfo=mfileInfo;
?? ??? ?}
??????? public void run() {
?????? ??? ?HttpURLConnection conn=null;
?????? ??? ?RandomAccessFile raf=null;
??????????? try{
?????????????? //鏈接網(wǎng)絡(luò)文件
?????????? ??? ?URL url=new URL(mFileInfo.geturl());
?????????? ??? ? conn=(HttpURLConnection)url.openConnection();
?????????? ??? ? conn.setConnectTimeout(5000);
???????????????? conn.setRequestMethod("GET");
??????????????? int length=-1;
??????????????? if(conn.getResponseCode()==206){
?????????????????? //獲得文件長(zhǎng)度
?????????????? ??? ?length=conn.getContentLength();
??????????????? }
??????????????? if(length<=0){
?????????????? ??? ?return;
??????????????? }
??????????????? //在本地創(chuàng)建文件
??????????????? File dir=new File(SAVE_PATH);
??????????????? if(!dir.exists()){
?????????????? ??? ?dir.mkdir();
??????????????? }
??????????????? File file=new File(dir,mFileInfo.getfileName());
??????????????? raf=new RandomAccessFile(file,"rwd");
??????????????? raf.setLength(length);
?????????????? ?
??????????????? //設(shè)置文件長(zhǎng)度,用MyHandler的對(duì)象傳遞Message到被繼承的Handler方法中
??????????????? mFileInfo.setlength(length);
??????????????? Message message=Message.obtain();
???????????????? message.what=MSG_INIT;
???????????????? message.obj=mFileInfo;
???????????????? myHandler.sendMessage(message);
??????????? }catch(Exception e){
?????????? ??? ?e.printStackTrace();
??????????? }finally{
?????????? ??? ?try {
?? ??? ??? ??? ??? ?raf.close();
?? ??? ??? ??? ??? ?conn.disconnect();
?? ??? ??? ??? ?} catch (IOException e) {
?? ??? ??? ??? ??? ?// TODO Auto-generated catch block
?? ??? ??? ??? ??? ?e.printStackTrace();
?? ??? ??? ??? ?}
??????????? }
??????? }
??? }

?? ?
?? ?
???

正在回答

1 回答

http://img1.sycdn.imooc.com//5726c2df0001e47a13270388.jpg

每次都報(bào)這樣的異常,,,,和解呀

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
Android-Service系列之?dāng)帱c(diǎn)續(xù)傳下載
  • 參與學(xué)習(xí)       20431    人
  • 解答問題       99    個(gè)

想升職加薪么?本章課程你值得擁有,滿滿的干貨,學(xué)起來吧

進(jìn)入課程

在service中調(diào)用子線程報(bào)異常

我要回答 關(guān)注問題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)