안드로이드 개발 질문/답변
(글 수 45,052)
aidl의 구성은 데이터를 반환하는 String getData( );와 데이터를 입력하는 void putData(String msg); 데이터가 null인지를 검사하는 boolean isData( );로 구성되어 있습니다. 아래 코드와 같습니다.
Deliver_data.Stub mBinder = new Deliver_data.Stub() {
String tmp = null;
public String getData() throws RemoteException {
// TODO Auto-generated method stub
if(tmp != null)
return tmp;
else
return " ";
}
public void putData(String msg) throws RemoteException {
// TODO Auto-generated method stub
tmp = msg;
}
public boolean isData() throws RemoteException {
// TODO Auto-generated method stub
if(!tmp.equals(null))
return false;
else
return true;
}
};
그리고 메인액티비티에서는 아래와 같이 isData( )의 상태가 true인지 false인지 검사하여 데이터를 textview로 나타내 주려고 합니다.
try {
if(data.isData())
tmp = data.getData();
else
tmp = " ";
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}//intent.getCharSequenceExtra(Test_Service.TICKER));
text1.setText(tmp)
그런데 문제는 위와 같이 할때 데이터가 기존에 미리 들어있으면 상관이 없는데 데이터가 기존에 null이거나 없는 경우는 unexpectedly에러가 발생하게 됩니다. 바로 메인액티비티 소스의 2번째줄 if(data.isData( )) 이부분에서 말이죠!! 해결책이 있을까요? 책에도 더 자세한 내용이 없고 인터넷을 찾아봐도 aidl에 대한 자료는 그리 많지 않아서 질문 하게 되었습니다. 꼭 답변 부탁드리겠습니다. 필요하시다면 전체소스도 보여 드릴 순 있습니다.




temp != null 으로 하는거 아닌가요?