마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

쓰레드 함수 콜 방안 좀 알려주세요

0 추천
class DataThread extends Thread implements Runnable {
    	final Handler handler = new Handler();
        public DataThread() {
        	mstop = true;
        }
        public void stopThread() {
        	mstop = !mstop;
        }
        @Override
        public void run() {
            super.run();
            while (mstop) {
            	while(isStop)
            	{
            		try { 
                		Thread.sleep(500); 
                	}catch (InterruptedException e) { 
                		e.printStackTrace(); 
                     }
            		//Log.e(TAG, "쓰레드 대기 상태입니다...............대기 중 대기 중....");
            	}
            	
            	if((btnflag == true) && (datanumbering > 0)) {
            		byte[] command = new byte[8];
                	address = 0;
                	Log.e(TAG, "데이타  갯수는......"+ datanumbering);
                	while(address < datanumbering) {
                		ksjflag = false;
                		command[0] = (byte)0xAA;
                        command[1] = (byte)0x55;
                        command[2] = (byte)5;
                        command[3] = (byte)52;  //COM_READ_EACH_DATA
                        command[4] = (byte)(address & 0xFF);
                        command[5] = (byte)((address >> 8) & 0xFF);
                        command[6] = (byte)((address >> 16) & 0xFF);
                        command[7] = (byte)((address >> 24) & 0xFF);
        	    		mBluetoothLeService.writeCharacteristic(mBluetoothGattChar, command); 
        	    		Log.e(TAG, " 52번 커맨드 날라갑니다..............받아라....................");
        	    		while (ksjflag == true) {  // ready finish read data
      						 try{
      				            Thread.sleep(10);
      				         }catch(InterruptedException e) {
      				            e.printStackTrace();
      				          }
      						 bleRespWaitTime++;
      				         if(bleRespWaitTime >= 100)
      				         {
      				        	 break;
      				         }
        	    		} // whhile endreadflag end..
        	    		Log.e(TAG, " 52번 커맨드 	받았고 데이타 읽기 완료하였다 ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ.");
        	    		bleRespWaitTime = 0;
        	    		
        	    		//listInit();
            			//adapter.notifyDataSetChanged();	
        	    		
        	    		mpmeachdataflag = true;
        	    		try{ 
                    	    Thread.sleep(700); 
                    	} catch (InterruptedException e) { 
                    			e.printStackTrace(); 
                    	  }
        	    		 address ++;
                	} // while(address < datanumbering) end..
                	Log.e(TAG, "데이타 다 읽었습니다................................................^^");
                	isStop = true;
                	btnflag = false;
            	} // if(btnflag == true) end..
            	
            	mdataThread.stopThread();
            	//popupflag = true;
            	//mpmeachdataflag = false;
            } //while (mstop) end..
        }
    }

 

쓰레드 내에서 다음 함수 2개를 호출하고 싶은데...

방안이 생각이 안나요....

도와주세요~~

//listInit();
            			//adapter.notifyDataSetChanged();
 
앤드류이드 (6,190 포인트) 님이 2016년 4월 20일 질문

1개의 답변

0 추천
 
채택된 답변
listInit()이 어떤 함수인지는 모르겠지만

아래의 notify는 ui변경 작업이 일어나기 떄문에, 스레드에서 호출이 불가능하죠.

핸들러로 메세지를 보낸 후

핸들러에서 처리하셔야 합니다.
모나미153 (17,540 포인트) 님이 2016년 4월 20일 답변
앤드류이드님이 2016년 4월 21일 채택됨
...