在我的活动中,我有一个文本字段,它必须填写从JSON调用收到的一些数据。如果我是第一次打开活动,则该字段为空;但是,如果我从活动中退出然后我重新打开它(或者,如果我将手机置于待机状态并重新激活它),则JSON正常工作并且字段中填充了正确的数据。很奇怪!我该如何解决?我复制下面的活动。谢谢!
package com.mycom.myapp.Views;
import android.app.Activity;
import android.content.Intent;
import android.location.Location;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.ImageButton;
import android.widget.TextView;
import com.mycom.myapp.R;
import com.mycom.myapp.Utility.ClsJSONProcess;
import java.util.ArrayList;
public class MyActivity extends Activity {
private TextView ConditionField;
String urlString = "";
String AlertText="";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_myactivity);
ConditionField = (TextView) findViewById(R.id.myActivityGuardMessage);
urlString="https://myurl.com/point?latitude=46.501616&longitude=11.340313&radius=0.5";
//This is the JSON code!
ClsJSONProcess ActiveProcess = new ClsJSONProcess();
ActiveProcess.execute(urlString);
int JSONArrayLength = ActiveProcess.getJSONArrayLength();
String JSONArray[][] = new String[ActiveProcess.getJSONArrayLength()][9];
if (ActiveProcess.getJSONArray() != null) {
AlertText = AlertText + ActiveProcess.getJSONArray()[0][1]
}
ConditionField.setText(AlertText);
}
}