Android: what is the best way to store JSON data offline for the app in android?

前端 未结 3 837
心在旅途
心在旅途 2021-02-05 18:42

I want to implement an app, that will show the route number, the rider has boarded in google map. So to find the route number I need some information about the routes, which are

3条回答
  •  深忆病人
    2021-02-05 19:11

    Maybe you can save them using SharedPreferences. You can store a json object/array by doing:

    Saving json to SharedPreferences:

        PreferenceManager.getDefaultSharedPreferences(context).edit()
    .putString("theJson",jsonObject.toString()).apply();
    

    Getting the stored json:

    JsonObject jsonObject = PreferenceManager.
    getDefaultSharedPreferences(this).getString("theJson","");
    

提交回复
热议问题