当前位置: 首页 > news >正文

用网站模板给人做网站挣钱吗杭州网站设计成功柚v米科技

用网站模板给人做网站挣钱吗,杭州网站设计成功柚v米科技,wordpress调用指定id目录,怎样自己做网站赚钱关于作者#xff1a;CSDN内容合伙人、技术专家#xff0c; 从零开始做日活千万级APP。 专注于分享各领域原创系列文章 #xff0c;擅长java后端、移动开发、人工智能等#xff0c;希望大家多多支持。 目录 一、导读二、概览三、使用3.1 Preferences DataStore添加依赖数据读… 关于作者CSDN内容合伙人、技术专家 从零开始做日活千万级APP。 专注于分享各领域原创系列文章 擅长java后端、移动开发、人工智能等希望大家多多支持。 目录 一、导读二、概览三、使用3.1 Preferences DataStore添加依赖数据读写 3.2 ProtoDataStore添加依赖数据读写 3.3、在同步代码中使用 DataStore3.4、在多进程代码中使用 DataStore 四、DataStore MMKV五、 推荐阅读 一、导读 我们继续总结学习Java基础知识温故知新。 二、概览 DataStore 是一种用于 Android 应用程序数据存储的新的推荐方式。 它是在 Android Jetpack 组件中引入的旨在替代 SharedPreferences并提供更强大、易于使用的 API。 DataStore 基于 Kotlin 协程和 Flow 构建而成 提供了一种类型安全且异步的数据存储解决方案。 相比于 SharedPreferencesDataStore 具有以下优点 异步操作DataStore 提供了异步的读写操作避免了阻塞主线程的问题。这使得在读取和写入数据时应用程序可以更好地保持响应性能。 类型安全DataStore 支持使用协议缓冲区Protocol Buffers来定义数据模型这样可以确保在编译时进行类型检查。数据模型的更改不会导致运行时错误而是在编译时进行检测。 支持多种数据类型DataStore 支持存储不同类型的数据包括原始类型、对象或自定义类。 数据一致性DataStore 提供了一致性和安全性保证保证在多个写入操作中的数据一致性。 流式数据访问DataStore 支持使用流Flow来访问数据使得可以轻松地观察数据的变化并进行相应的更新。 DataStore 提供了两个主要的实现方式PreferencesDataStore 和 ProtoDataStore。 PreferencesDataStore 适用于存储简单的数据类型使用键值对来存储数据。 ProtoDataStore 则使用 Protocol Buffers 定义数据模型并支持存储更复杂的数据结构类型化对象。 三、使用 3.1 Preferences DataStore 适用于存储简单的数据类型使用键值对来存储数据 添加依赖 // Preferences DataStore (SharedPreferences like APIs)dependencies {implementation androidx.datastore:datastore-preferences:1.0.0// optional - RxJava2 supportimplementation androidx.datastore:datastore-preferences-rxjava2:1.0.0// optional - RxJava3 supportimplementation androidx.datastore:datastore-preferences-rxjava3:1.0.0}// Alternatively - use the following artifact without an Android dependency.dependencies {implementation androidx.datastore:datastore-preferences-core:1.0.0} 数据读写 RxDataStorePreferences dataStore new RxPreferenceDataStoreBuilder(context, /*name*/ settings).build();Preferences.KeyInteger EXAMPLE_COUNTER PreferencesKeys.int(example_counter);FlowableInteger exampleCounterFlow dataStore.data().map(prefs - prefs.get(EXAMPLE_COUNTER));SinglePreferences updateResult dataStore.updateDataAsync(prefsIn - {MutablePreferences mutablePreferences prefsIn.toMutablePreferences();Integer currentInt prefsIn.get(INTEGER_KEY);mutablePreferences.set(INTEGER_KEY, currentInt ! null ? currentInt 1 : 1);return Single.just(mutablePreferences); }); // The update is completed once updateResult is completed.3.2 ProtoDataStore 使用 Protocol Buffers 定义数据模型并支持存储更复杂的数据结构 添加依赖 // Typed DataStore (Typed API surface, such as Proto)dependencies {implementation androidx.datastore:datastore:1.0.0// optional - RxJava2 supportimplementation androidx.datastore:datastore-rxjava2:1.0.0// optional - RxJava3 supportimplementation androidx.datastore:datastore-rxjava3:1.0.0}// Alternatively - use the following artifact without an Android dependency.dependencies {implementation androidx.datastore:datastore-core:1.0.0} 数据读写 Proto DataStore 要求在 app/src/main/proto/ 目录的 proto 文件中保存预定义的架构。 此架构用于定义在 Proto DataStore 中保存的对象的类型。 syntax proto3;option java_package com.example.application; option java_multiple_files true;message Settings {int32 example_counter 1; }private static class SettingsSerializer implements SerializerSettings {Overridepublic Settings getDefaultValue() {Settings.getDefaultInstance();}Overridepublic Settings readFrom(NotNull InputStream input) {try {return Settings.parseFrom(input);} catch (exception: InvalidProtocolBufferException) {throw CorruptionException(“Cannot read proto.”, exception);}}Overridepublic void writeTo(Settings t, NotNull OutputStream output) {t.writeTo(output);} }RxDataStoreByte dataStore new RxDataStoreBuilderByte(context, /* fileName */ settings.pb, new SettingsSerializer()).build();FlowableInteger exampleCounterFlow dataStore.data().map(settings - settings.getExampleCounter());SingleSettings updateResult dataStore.updateDataAsync(currentSettings -Single.just(currentSettings.toBuilder().setExampleCounter(currentSettings.getExampleCounter() 1).build())); 3.3、在同步代码中使用 DataStore DataStore 的主要优势之一是异步 API但可能不一定始终能将周围的代码更改为异步代码。如果您使用的现有代码库采用同步磁盘 I/O或者您的依赖项不提供异步 API就可能出现这种情况。 Kotlin 协程提供 runBlocking() 协程构建器以帮助消除同步与异步代码之间的差异。您可以使用 runBlocking() 从 DataStore 同步读取数据。RxJava 在 Flowable 上提供阻塞方法。以下代码会阻塞发起调用的线程直到 DataStore 返回数据 Settings settings dataStore.data().blockingFirst();dataStore.data().first().subscribe(); 这样DataStore 可以异步读取数据并将其缓存在内存中。以后使用 runBlocking() 进行同步读取的速度可能会更快或者如果初始读取已经完成可能也可以完全避免磁盘 I/O 操作。请尽可能避免在 DataStore 数据读取时阻塞线程。阻塞界面线程可能会导致 ANR 或界面卡顿而阻塞其他线程可能会导致死锁。 3.4、在多进程代码中使用 DataStore DataStore 多进程功能目前仅在 1.1.0 Alpha 版中提供 为了能够在不同进程中使用 DataStore需要使用 MultiProcessDataStoreFactory 构造 DataStore 对象。 val dataStore: DataStoreSettings MultiProcessDataStoreFactory.create(serializer SettingsSerializer(),produceFile {File(${context.cacheDir.path}/myapp.preferences_pb)} )四、DataStore MMKV 看一组数据对比图片来源于MMKV 开源网站 至于如何使用就不描述了非常简单。 个人感觉 DataStore 没有 MMKV 好用推荐使用 MMKV但是各有优劣吧。 jetpack 官网 datastore 五、 推荐阅读 Java 专栏 SQL 专栏 数据结构与算法 Android学习专栏
http://www.sczhlp.com/news/210598/

相关文章:

  • 网站开发工程师岗位说明书菏泽县建设局网站
  • 网站建设的销售话术网站建设制作心得团队
  • 注册网站是哪个部门公司做一个网站如何定位
  • 黔南州建设局门户网站电商网站 厦门
  • 找别人做网站一定注意什么做网页游戏怎么赚钱
  • 学校网站设计的作用新手做外贸怎么入门
  • 2025年保洁公司权威推荐榜单:驻场/钟点/开荒/外包/商场/办公楼/工厂/医院/企业保洁服务优选指南
  • 35跬步本手@数学学习+计算机学习+语言学习@20251019
  • 【容器日志采集】【 四】消费kafka保存到es
  • 嵌入式实验3串口通信---任务二串口传输文件实验
  • 网站源码 带后台北京工程建设
  • 找人网站长沙娱乐网站开发
  • 网站防止挂马应该怎么做快速搭建网站推荐
  • 东莞市建设监督网站局网站建设自查
  • 备案网站名称修改二手域名购买已备案
  • 企业免费做网站有哪些可以做翻译兼职的网站吗
  • qq空间网站是多少wordpress重复链接
  • 重庆网站制作公司哪家好佛山网站建设公司排行
  • 企业网站源代码下载装饰设计是什么
  • 服务器网站管理软件重庆市建筑工程信息官方网站
  • ICP网站忘记密码建设文化网站的目的和意义
  • 建设网站怎么做琼海网站建设公司
  • 品牌营销与市场营销的区别seo网上培训
  • jsp网站怎么运行seo是哪里
  • wordpress影视源码seo标题是什么
  • 苏州吴中区建设局工程网站网页设计图片怎么放进去
  • 商水住房城乡建设网站适合站长做的网站
  • 什么网站做微信公众账号硬件开发用什么语言
  • 自助建设视频网站十个常见的网络推广渠道
  • 长治市住房保障和城乡建设管理局网站做网站的程序员