1
이 코드는이 코드를 개선하는 방법을 알려주고 있습니다. 내가 AsyncTask를 함께 시도하고 나는이 코드에서 작동하도록 어차피 :이 코드를 실행하면 ANR 강제 닫기
무엇 내가 여기서 뭘하려고하는 것은 활동이 최신 버전을 확인하고 새로운 버전을 가지고 경우가 사용자에게 물어에 AlertDialog 를 나타납니다 업데이트 프로그램입니다 시장에서의 업데이트
public class Updater extends Activity {
private int newVerCode = 0;
private String newVerName = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
if (getServerVerCode()) {
int vercode = Config.getVerCode(this);
if (newVerCode > vercode) {
doNewVersionUpdate();
} else {
notNewVersionShow();
}
}
}
//check version using json
private boolean getServerVerCode() {
try {
String verjson = NetworkTool.getContent(Config.UPDATE_SERVER
+ Config.UPDATE_VERJSON);
JSONArray array = new JSONArray(verjson);
if (array.length() > 0) {
JSONObject obj = array.getJSONObject(0);
try {
newVerCode = Integer.parseInt(obj.getString("verCode"));
newVerName = obj.getString("verName");
} catch (Exception e) {
newVerCode = -1;
newVerName = "";
return false;
}
}
} catch (Exception e) {
return false;
}
return true;
}
//Found No new version
private void notNewVersionShow() {
Updater.this.finish(); // End updater activity
}
//Found New version
private void doNewVersionUpdate() {
//Display alertdialog
}
}
와우! 감사 ! 그게 빠르다, 나는 여전히 그것을 구현하려고 노력했다. – xAnGz