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;
}
...全文
428 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jing丶無雙 2017-12-01
  • 打赏
  • 举报
回复
1.检查有无错误提示 2.断点调试,看代码执行到哪一步,从而找到没有执行写入操作的原因
Contents Acknowledgments xxxi About the Authors xxxiii Introduction 1 Who Should Read This Book 1 Key Questions Answered in This Book 2 How This Book Is Structured 2 An Overview of Changes in This Edition 3 Development Environments Used in This Book 5 Supplementary Materials Available 6 Where to Find More Information 6 Conventions Used in This Book 7 Contacting the Authors 7 I: An Overview of the Android Platform 1 Introducing Android 11 A Brief History of Mobile Software Development 11 Way Back When 11 “The Brick” 13 Wireless Application Protocol (WAP) 15 Proprietary Mobile Platforms 17 The Open Handset Alliance 18 Google Goes Wireless 18 Forming the Open Handset Alliance 19 Manufacturers: Designing Android Devices 19 Mobile Operators: Delivering the Android Experience 20 Apps Drive Device Sales: Developing Android Applications 21 Taking Advantage of All Android Has to Offer 22 The Android Marketplace: Where We Are Now 22 Android Platform Differences 23 Android: A Next-Generation Platform 23 Free and Open Source 25 Familiar and Inexpensive Development Tools 25xii Contents Reasonable Learning Curve for Developers 26 Enabling Development of Powerful Applications 26 Rich, Secure Application Integration 26 No Costly Obstacles for Development 27 A “Free Market” for Applications 27 A Growing Platform 28 The Android Platform 29 Android’s Underlying Architecture 29 Security and Permissions 31 Exploring Android Applications 32 Summary 36 Quiz Questions 36 Exercises 36 References and More Information 36 2 Setting Up Your Android Development Environment 37 Configuring Your Development Environment 37 Configuring Your Operating System for Device Debugging 39 Configuring Your Android Hardware for Debugging 39 Upgrading the Android SDK 42 Problems with the Android Software Development Kit 42 Exploring the Android SDK 43 Understanding the An

80,349

社区成员

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

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