0
AsyncTask의 onPostExecute 메서드에서 RunOnUIThread Runnable의 setText 메서드로 textView를 업데이트하고 있습니다.RunOnUIThread에서 뷰 업데이트 작업이 다시 시작될 때까지 작동
처음 활동을 실행하면 textView가 업데이트됩니다. 그러나 다른 활동으로 가서 이전 활동으로 돌아 가면 더 이상 UI를 업데이트하지 않습니다.
디버거를 사용하여 textView의 mText 필드가 새 텍스트로 업데이트되고 있음을 알 수 있습니다. 그러나 코드를 계속 실행하면 textView가 기본 텍스트로 유지됩니다.
여기에 뭔가가 있습니까? 왜 이것이 사실이되어야하는지 나는 정말로 알 수 없다.
이것은 onPostExecute입니다. 필드가 업데이트되는 방법은 checkAgainstLocations입니다()이() 메소드 checkAgainstLocations이다
@Override
protected void onPostExecute(final ArrayList<String> strings) {
super.onPostExecute(strings);
if (strings == null) {
Toast.makeText(ctx, "Please check you have an internet connection", Toast.LENGTH_LONG).show();
return;
}
locationsData = cleanLocations(strings);
if (locationsData.size() < 1) {
locationsData.add("Choose a location...");
} else if (!locationsData.get(0).equals("Choose a location...")) {
locationsData.add(0, "Choose a location...");
}
adaptor.clear();
adaptor.addAll(locationsData);
adaptor.notifyDataSetChanged();
changeLocationButton.setEnabled(true);
if (mCurrentLocation != null) {
checkAgainstLocations();
}
}
(아래 참조).
private void checkAgainstLocations() {
Geocoder gcd = new Geocoder(this, Locale.getDefault());
List<Address> addresses = new ArrayList<>();
if (myLocation != null) {
try {
addresses = gcd.getFromLocation(myLocation.getLatitude(), myLocation.getLongitude(), 1);
} catch (IOException e) {
Log.e("loc", "no location yet");
}
}
if (addresses.size() > 0) {
myCity = addresses.get(0).getLocality().toLowerCase();
} else {
myCity = "National";
}
new LoadPromotions().execute(myCity);
if (locationsData.contains(myCity.toLowerCase())) {
if (!userSelected) {
locationsResult = myCity.toLowerCase();
currentLocation.setText(locationsResult);
currentLocation.postInvalidate();
}
}
}
투 셔 (Tushar)에게 감사드립니다. 이것이 실제로 문제였습니다. 나 자신을 생각하지 않았다는 것을 믿을 수 없다. – Cross2four