내 앱이 처음으로 59kb의 txt 파일 인 사용자 계약서를 보여주기 시작했을 때. Text View에 파일을 읽고 추가하는 데 시간이 걸리기 때문에 비동기 작업에서 텍스트 파일을 추가하고 진행하는 동안 진행률 막대를 표시하기로 결정했지만 파일이 텍스트보기에 추가 될 때까지 진행률 막대가 고정됩니다. 그런 일이 발생하면 앱이 응답하기까지 시간이 걸리고 때로는 ANR이 발생합니다. 여기 내 비동기 작업 코드 :AsyncTask 동안 UI가 멈춤
public class DownloadFilesTask extends AsyncTask<String, Integer, String> {
AlertDialog alertDialog = null;
Button getstarted, cancel;
TextView text2;
AlertDialog.Builder builder;
LayoutInflater inflater = (LayoutInflater) Profile.this.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.agreement, (ViewGroup) findViewById(R.id.layout_root));
protected void onPreExecute(){
progressDialog = ProgressDialog.show(Profile.this, "", "Loading.....", true);
getstarted=(Button) layout.findViewById(R.id.get_started);
cancel=(Button) layout.findViewById(R.id.cancel);
cancel.setVisibility(View.GONE);
text2 = (TextView) layout.findViewById(R.id.ag);
builder = new Builder(Profile.this);
builder.setView(layout);
alertDialog = builder.create();
alertDialog.setCancelable(false);
alertDialog.setTitle(getString(R.string.terms));
}
@Override
protected String doInBackground(String... arg0) {
StringBuilder sb = new StringBuilder();
try {
AssetManager am = getAssets();
InputStream in = am.open("EULA.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
in.close();
} catch(Exception e){
System.out.println("FILE NOT FOUND : "+ e.getMessage());
}
return sb.toString();
}
// This is called when doInBackground() is finished
protected void onPostExecute(String result) {
progressDialog.dismiss();
alertDialog.show();
text2.setText(Html.fromHtml(result));
}
// This is called each time you call publishProgress()
}
제가 알기로는 파일을 postExecute 메서드의 텍스트보기에 추가했습니다. 파일을 읽는 방식을 변경해야합니까? 또는 다른 것입니다. 미리 감사드립니다.
어떻게 'AsyncTask'를 호출합니까? – codeMagic
변호사세요? 사용자 동의를 위해 59K ?? 나는 사용자 동의가 오랫동안 당신을 보호 할 것이라고 생각하지 않습니다. 왜냐하면 사용자가 읽고 동의하는 것이 불가능하기 때문입니다. 중요한 내용을 담은 매우 짧은 탄환 목록을 작성하고 외부 웹 페이지에 대한 완전한 합의에 대한 링크를 제공해야합니다. – auval
나는 알고있다. 그러나 상사는 클라이언트와의 이전의 문제 때문에 그 동의를 원한다. 저를 믿으십시오, 나는 그것을 더 짧게 만들 것을 제안했다, 운이 없다. – wnieves19