Piyush kumar
Piyush kumar

Reputation: 33

How to Store String[] in android studio app?

I was just trying out this code but it subsequently turned my phone into a black screen and after some time of black screen it was able to load data.

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

Can anyone please tell me the way to Escape from that black screen?

Upvotes: 1

Views: 206

Answers (2)

Joseph Ofem
Joseph Ofem

Reputation: 384

You can as well execute the code in the runUiThread method...

//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();
   }
});

Upvotes: 1

Vishnu
Vishnu

Reputation: 785

Try using this

AsyncTask.execute(new Runnable() {
            @Override
            public void run() {
                Gson gson = new Gson();
                String json = gson.toJson(my_Arraylist < String > _here);
                editor.putString("task list", json);
                editor.apply();
            }
        });

Hope this helps. Feel free to ask for clarifications...

Upvotes: 0

Related Questions