首页 > 解决方案 > 如何在 android studio 应用程序中存储字符串 []?

问题描述

我只是在尝试这段代码,但它随后将我的手机变成了黑屏,并且在黑屏一段时间后它能够加载数据

    Gson gson = new Gson();
    String json = gson.toJson(my_Arraylist<String>_here);
    editor.putString("task list", json);
    editor.apply();

谁能告诉我逃离那个黑屏的方法?

标签: javaandroidarraysandroid-studio

解决方案


您也可以在 runUiThread 方法中执行代码...

//This method will run your code in the background and update the UI when it is don
runUiThread(new Runnable(){
   @Override
   public void run(){
     //Your code here
     Gson gson = new Gson();
     String json = gson.toJson(my_Arraylist<String>_here);
     editor.putString("task list", json);
     editor.apply();
   }
});

推荐阅读