Activity加了android:theme="@android:style/Theme.NoDisplay"之后程序运行有问题
程序如下,我想实现程序运行无界面,请求服务器json数据,解析之后保存在一个Properties 文件中,但是不加android:theme="@android:style/Theme.NoDisplay"还好,运行程序能建立文件保存数据,加了之后,没有数据被保存,请问是什么问题?
private Properties prop;
private Context mcontext;
private String fileSavePath;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String sdpath = Environment.getDataDirectory()+"";
fileSavePath = sdpath + "/config.properties";
prop=loadConfig(mcontext,fileSavePath);
if(prop==null){
//配置文件不存在的时候创建配置文件 初始化配置信息
prop=new Properties();
saveConfig(mcontext,fileSavePath,prop);
}
sendRequestWithHttpClient();
}
private void sendRequestWithHttpClient() {
new Thread(new Runnable() {
@Override
public void run() {
try{
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("http://10.88.253.215:8080/test/testurl.json")
.build();
Response response = client.newCall(request).execute();
String responseData = response.body().string();
JSONObject jsonObject = null;
jsonObject = new JSONObject(responseData);
Iterator iterator = jsonObject.keys();
while(iterator.hasNext()){
try {
String key = (String) iterator.next();
String value = jsonObject.getString(key);
prop.put(key,value);
saveConfig(mcontext,fileSavePath,prop);
} catch (Exception e) {
e.printStackTrace();
}
}
}catch(Exception e){
e.printStackTrace();
}
}
}).start();
}
//读取配置文件
public static Properties loadConfig(Context context, String file) {
Properties properties = new Properties();
InputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(file));
properties.load(new InputStreamReader(in, "utf-8"));
} catch (Exception e) {
e.printStackTrace();
return null;
}
return properties;
}
//保存配置文件
public static boolean saveConfig(Context context, String file, Properties properties) {
FileOutputStream s = null;
try {
s = new FileOutputStream(file, false);
properties.store(new OutputStreamWriter(s, "utf-8"), "");
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}