IntentService 에 서 는 Toask 를 사용 하여 dead 스 레 드 에서 Handler 에 게 메 시 지 를 잘못 보 냅 니 다.
1650 단어 IntentServiceonHandleIntent
The problem here is that you are creating a Toast inside a thread that is managed by the IntentService. The system will use the Handler associated with this thread to show and hide the Toast.
First the Toast will be shown correctly, but when the system tries to hide it, after the onHandleIntent method has finished, the error "sending message to a Handler on a dead thread" will be thrown because the thread on which the Toast was created is no longer valid, and the Toast will not disappear.
문 제 는 IntentService 가 관리 하 는 Toast 내부 스 레 드 를 만 들 고 있 습 니 다.이 시스템 은 Toast 를 표시 하고 숨 기기 위해 이 스 레 드 와 연 결 된 처리 프로그램 을 사용 합 니 다.우선,Toast 는 정확하게 표 시 됩 니 다.그러나 시스템 이 이 를 숨 기 려 고 할 때 onHandleIntent 방법 이 완료 되 었 습 니 다."sending message to a Handler on a dead thread"의 오 류 는 버 려 집 니 다.Toast 가 그 위 에 만 든 스 레 드 가 더 이상 유효 하지 않 고 Toast 가 사라 지지 않 기 때 문 입 니 다.
해결 방법:
// create a handler to post messages to the main thread
Handler mHandler = new Handler(getMainLooper());
mHandler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), "test", Toast.LENGTH_SHORT).show();
}
});
참조:http://www.xuebuyuan.com/36739.html
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
IntentService 에 서 는 Toask 를 사용 하여 dead 스 레 드 에서 Handler 에 게 메 시 지 를 잘못 보 냅 니 다.자신의 IntentSevice 계승 클래스 의 onHandleIntent 방법 에 Toast.makeText(getApplication Context(),"sd 는 존재 하지 않 습 니 다",Toast.LENGTHS...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.