初始化只需要一次就行了 放在你最开始执行的activity里面 或者 application
Hawk.init(this)
.setEncryptionMethod(HawkBuilder.EncryptionMethod.MEDIUM)
.setStorage(HawkBuilder.newSqliteStorage(this))
.setLogLevel(LogLevel.FULL)
.build();
能使用高安全级别 初始化可能需要 36-400ms 并且需要你提供密码
Hawk.init(this)
.setEncryptionMethod(HawkBuilder.EncryptionMethod.HIGHEST)
.setStorage(HawkBuilder.newSqliteStorage(this))
.setLogLevel(LogLevel.FULL)
.build();
初始化可以选择 SQLite 或者 SharePreference
.setStorage(HawkBuilder.newSqliteStorage(this))
or
.setStorage(HawkBuilder.newSharedPrefStorage(this))
(三) 存数据
Hawk.put(key, T); // Returns the result as boolean
您还可以通过使用链功能存储多个项目。记得在最后使用commit()。
// Returns the result as boolean
Hawk.chain()
.put(KEY_LIST, List)
.put(KEY_ANOTHER,“test”)
.commit();
(四) 取数据
T result = Hawk.get(key);
or