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

thread에서 timeout 설정 하는 방법 질문 합니다.

0 추천
private void GetNowLoc(Double... location) {
		final double lat = location[0];
		final double lon = location[1];
		pDlg = ProgressDialog.show(BbabangMain.this, "", getString(R.string.main_nowloc_search), true);
		new Thread(new Runnable() {
			public void run() {
				runOnUiThread(new Runnable() {
					public void run() {

					}
				});
				getNowLoc(lat, lon);
			}
		}).start();
	}

	public void getNowLoc(Double... location) {
		final double mLat = location[0];
		final double mLon = location[1];
		try {
			runOnUiThread(new Runnable() {
				public void run() {
					Geocoder gc = new Geocoder(BbabangMain.this, Locale.KOREAN);
					String addressString = "No address found";
					try {
						List<Address> addresses = gc.getFromLocation(mLat, mLon, 1);
						StringBuilder sb = new StringBuilder();

						if (addresses.size() > 0) {
							Address address = addresses.get(0);
							for (int i = 0; i < address.getMaxAddressLineIndex(); i++)
								sb.append(address.getAddressLine(i)).append("\n");
								sb.append(address.getAdminArea()).append(" "); // 시
								sb.append(address.getLocality()).append(" "); // 구
								sb.append(address.getThoroughfare()).append(" "); // 동
								addressString = sb.toString();
						}
						NowLocSearchDialog(addressString, mLat, mLon);
						pDlg.dismiss();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			});
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

위 코드처럼 

Geocoder로 현재 위치를 입력하면 주소를 받아오고 있습니다.

궁금한 점이 이때 만약 10초던 20초던 데이터를 받아오지 못하는 경우 프로그레스다이얼로그가 계속 돌고있습니다.

timeout설정을 하려면 어떻게 해야할까요?ㅠㅠ

뱅구다 (11,280 포인트) 님이 2015년 2월 2일 질문

1개의 답변

+1 추천
위치 refresh 할 때 20초 후에 핸들러한테 타임아웃 처리하라고 던져놓고

성공적으로 받은 경우에는 핸들러한테 던졌던 메시지를 삭제하도록 처리하시면 될 듯 하네요
Gradler (109,780 포인트) 님이 2015년 2월 2일 답변
...