2018년 4월 9일 월요일

안드로이드 서비스에서 UI에 해당하는 Toast message 출력하기


안드로이드 서비스에서 UI에 해당하는 Toast message 출력하기

서비스 )
public class MsSvcBedalDhBackgroundSvc extends Service {
    ...
}



시스템 쓰레드 )
Runnable mRun = new Runnable() {
public void run() {
try{
while( bThreadGo ){
Log.i(TAG, ">mRun : 이거를 계속 탄다.");

iLoopValue++;

Thread.sleep(iThreadInterval);

if(iLoopValue>100000)iLoopValue=0;

positionSaveProc();

} //end while
}catch(Exception e){
e.printStackTrace();
}
}
};



UI 쓰레드의 호출 )
/*
 * 변경된 위치를 저장해준다.
 */
public synchronized void positionSaveProc(){

Log.i(TAG, ">positionSaveProc : loop call start ");

String sUnitBatchExecYn = getSharePreferenceStringValue("batch_exec_yn");

//로그인을 했기 때문에 가동해준다
if(sUnitBatchExecYn.equals("Y")){

//UI Thread
Message msg = new Message();
msg.what = 0;
msg.obj = null;
handler.sendMessage(msg); 
}
}


댓글 없음:

댓글 쓰기