Sp保存

SharedPreferences sp = getSharedPreferences("a", MODE_PRIVATE);
SharedPreferences.Editor edit = sp.edit();
edit.putBoolean("isFirst", false);
edit.putString("json", sb.toString());
edit.commit();
Result result = new Gson().fromJson(sb.toString(), Result.class);
Message msg = new Message();
msg.obj = result;
handler.sendMessage(msg);


private Handler handler = new Handler(new Handler.Callback() {
    @Override
    public boolean handleMessage(@NonNull Message msg) {
        Result res = (Result) msg.obj;
        List data = res.getData();
        datas.addAll(data);
        resultAdapter.notifyDataSetChanged();
        return false;
    }
});


SharedPreferences sp = getSharedPreferences("a", MODE_PRIVATE);
boolean isFirst = sp.getBoolean("isFirst", true);
if(isFirst){
    initData();
}else{
    String json = sp.getString("json", "");
    Result result = new Gson().fromJson(json, Result.class);
    List data = result.getData();
    datas.addAll(data);
    resultAdapter.notifyDataSetChanged();
}

*仅供参考

你可能感兴趣的:(andrioid)