Activity加了android:theme="@android:style/Theme.NoDisplay"之后程序运行有问题

qq_35633462 2017-12-01 10:46:08
程序如下,我想实现程序运行无界面,请求服务器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;
}
...全文
427 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jing丶無雙 2017-12-01
  • 打赏
  • 举报
回复
1.检查有无错误提示 2.断点调试,看代码执行到哪一步,从而找到没有执行写入操作的原因

80,349

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧