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

免费的网站开发软件制作一个网页的步骤

免费的网站开发软件,制作一个网页的步骤,盘锦建设工程信息网站,阿里巴巴怎么做企业网站ViewModel 概览 Android Jetpack 的一部分。 ViewModel 类是一种业务逻辑或屏幕级状态容器。它用于将状态公开给界面,以及封装相关的业务逻辑。 它的主要优点是,它可以缓存状态,并可在配置更改后持久保留相应状态。这意味着在 activity 之…

ViewModel 概览   Android Jetpack 的一部分。

ViewModel 类是一种业务逻辑或屏幕级状态容器。它用于将状态公开给界面,以及封装相关的业务逻辑。 它的主要优点是,它可以缓存状态,并可在配置更改后持久保留相应状态。这意味着在 activity 之间导航时或进行配置更改后(例如旋转屏幕时),界面将无需重新提取数据。

1.导包:

    //viewModel包// https://mvnrepository.com/artifact/androidx.lifecycle/lifecycle-viewmodel-ktximplementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'//runtimeOnly 用于声明一个只在运行时需要的依赖。这意味着这个依赖在编译时不需要,但在运行时需要。// 设为runtimeOnly 在编译时会提示有些包找不到比如 viewModels 提示没有  解决方法改为 implementation//implementation  依赖项作为编译和运行时的依赖。这意味着这个依赖在编译和运行时都是可见的。//工具类实现viewModel创建简化开发 2个包// https://mvnrepository.com/artifact/androidx.fragment/fragment-ktximplementation  'androidx.fragment:fragment-ktx:1.6.1'// https://mvnrepository.com/artifact/androidx.activity/activity-ktximplementation  'androidx.activity:activity-ktx:1.6.1'

2.ViewModel() 的创建 

写个类实现 ViewModel()

package com.exampleimport android.app.Application
import android.util.Log
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.ViewModel/*** ViewModel() 的创建* AndroidViewModel() 子类*/
class MyviewModel : ViewModel() {//初始化块init {Log.i("TAG", ": MyviewModel ViewModel 初始化")}//internal  只能在同一个模块或库中被访问,而不能在其他模块或库中被访问。internal fun getName(): String {return "---MyviewModel getName()方法-${System.currentTimeMillis()}"}//重新销毁方法override fun onCleared() {super.onCleared()Log.i("TAG", ": MyviewModel onCleared 销毁方法")}
}//AndroidViewModel(private val application: Application) : ViewModel()
class MyviewModelTwo(application: Application) : AndroidViewModel(application) {//初始化块init {Log.i("TAG", ": MyviewModelTwo AndroidViewModel 初始化")}fun getName(): String {return "---MyviewModelTwo getName()方法-${System.currentTimeMillis()}"}//重新销毁方法override fun onCleared() {super.onCleared()Log.i("TAG", ": MyviewModelTwo onCleared 销毁方法")}}

3.ViewModel 的3种使用方法

MainActivity

package com.exampleimport android.os.Bundle
import android.util.Log
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModelLazy
import androidx.lifecycle.ViewModelProviderclass MainActivity : AppCompatActivity() {//viewmodel使用1.代理 by ViewModelLazy 返回Lazy<VM>val vm1: MyviewModel by ViewModelLazy<MyviewModel>(MyviewModel::class,{ viewModelStore },{ defaultViewModelProviderFactory })//2.使用工具类导包方法简化写法 实现原理和上面一样//    implementation  'androidx.fragment:fragment-ktx:1.6.1'//    implementation  'androidx.activity:activity-ktx:1.6.1'val vm2: MyviewModel by viewModels<MyviewModel> { defaultViewModelProviderFactory }override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)Log.i("TAG", "---创建--onCreate")setContentView(R.layout.activity_main)//3.ViewModelProviderval vm3: MyviewModel = ViewModelProvider(viewModelStore,//这个对象只有在Activity创建之和才会有defaultViewModelProviderFactory).get(MyviewModel::class.java)//4 java 中方法  implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0-alpha03'
//         myViewModle = ViewModelProviders.of(this).get(MyViewModle.class);//val mviewModel = ViewModelProvider(this, ViewModelProvider.AndroidViewModelFactory(this.application))[MyviewModelTwo::class.java]// mviewModel.getName()//输出结果Log.i("MainActivity", "vm1.getName ${vm1.getName()}")Log.i("MainActivity", "vm2.getName ${vm2.getName()}")Log.i("MainActivity", "vm3.getName ${vm3.getName()}")}override fun onStart() {super.onStart()Log.i("TAG", "---开始--onStart")}override fun onResume() {super.onResume()Log.i("TAG", "---运行--onResume")}override fun onPause() {super.onPause()Log.i("TAG", "---暂停--onPause")}override fun onDestroy() {super.onDestroy()Log.i("TAG", "---销毁--onDestroy")}override fun onStop() {super.onStop()Log.i("TAG", "---停止--onStop")}override fun onRestart() {super.onRestart()Log.i("TAG", "---重新启动--onRestart")}}

Log 日志:

打开启动: ---创建--onCreate
: MyviewModel ViewModel 初始化
vm1.getName ---MyviewModel getName()方法-1704437476931
vm2.getName ---MyviewModel getName()方法-1704437476931
vm3.getName ---MyviewModel getName()方法-1704437476931
---开始--onStart
---运行--onResumehome 键退出:
---暂停--onPause
---停止--onStop重新打开:
---重新启动--onRestart
---开始--onStart---运行--onResume退出应用:
---暂停--onPause
---停止--onStop
: MyviewModel onCleared 销毁方法
---销毁--onDestroy

文章转载自:
http://dinncorubstone.ssfq.cn
http://dinncocranberry.ssfq.cn
http://dinncoanacidity.ssfq.cn
http://dinncogormless.ssfq.cn
http://dinncoutricle.ssfq.cn
http://dinncopaleobiochemistry.ssfq.cn
http://dinncogam.ssfq.cn
http://dinncochipmunk.ssfq.cn
http://dinncoregretful.ssfq.cn
http://dinncoaquaemanale.ssfq.cn
http://dinncouncial.ssfq.cn
http://dinncomaryolatrous.ssfq.cn
http://dinnconotchery.ssfq.cn
http://dinncoannexe.ssfq.cn
http://dinncoglycogenic.ssfq.cn
http://dinncononviolent.ssfq.cn
http://dinncobriefcase.ssfq.cn
http://dinncogrimy.ssfq.cn
http://dinncovictorian.ssfq.cn
http://dinncopowerbook.ssfq.cn
http://dinncorambutan.ssfq.cn
http://dinncoanthodium.ssfq.cn
http://dinncothalidomide.ssfq.cn
http://dinncomesophile.ssfq.cn
http://dinncocamera.ssfq.cn
http://dinncotinnitus.ssfq.cn
http://dinncoabduce.ssfq.cn
http://dinncopopularisation.ssfq.cn
http://dinncoextinctive.ssfq.cn
http://dinncotercentennial.ssfq.cn
http://dinncosweatproof.ssfq.cn
http://dinncoperioeci.ssfq.cn
http://dinncojowar.ssfq.cn
http://dinncoluck.ssfq.cn
http://dinncohyperaemia.ssfq.cn
http://dinnconouveau.ssfq.cn
http://dinncosexipolar.ssfq.cn
http://dinncospacelift.ssfq.cn
http://dinncooctopamine.ssfq.cn
http://dinncofrondose.ssfq.cn
http://dinncodynamoelectric.ssfq.cn
http://dinncoantalgic.ssfq.cn
http://dinncochayote.ssfq.cn
http://dinncorok.ssfq.cn
http://dinncoprodigious.ssfq.cn
http://dinncooop.ssfq.cn
http://dinncowimble.ssfq.cn
http://dinncorancidity.ssfq.cn
http://dinncoepiboly.ssfq.cn
http://dinncogelatinate.ssfq.cn
http://dinncounchangeably.ssfq.cn
http://dinncoslogging.ssfq.cn
http://dinncotribunary.ssfq.cn
http://dinncokrimmer.ssfq.cn
http://dinncoeyelid.ssfq.cn
http://dinncolanceted.ssfq.cn
http://dinncoonyx.ssfq.cn
http://dinncounsafe.ssfq.cn
http://dinncoclimatically.ssfq.cn
http://dinncorinker.ssfq.cn
http://dinncobsn.ssfq.cn
http://dinncoeblan.ssfq.cn
http://dinnconotate.ssfq.cn
http://dinncothibet.ssfq.cn
http://dinncoreferent.ssfq.cn
http://dinncopotentiostat.ssfq.cn
http://dinncoformularism.ssfq.cn
http://dinncodeepfry.ssfq.cn
http://dinncowimpish.ssfq.cn
http://dinncounskillfully.ssfq.cn
http://dinncosodomy.ssfq.cn
http://dinncoperspicacious.ssfq.cn
http://dinncosalvationism.ssfq.cn
http://dinncographite.ssfq.cn
http://dinncomainsail.ssfq.cn
http://dinncofusimotor.ssfq.cn
http://dinncogreed.ssfq.cn
http://dinncotile.ssfq.cn
http://dinncoexhale.ssfq.cn
http://dinncoescheatorship.ssfq.cn
http://dinncocarey.ssfq.cn
http://dinncoshrovetide.ssfq.cn
http://dinncoaerostat.ssfq.cn
http://dinncodryly.ssfq.cn
http://dinncolegendry.ssfq.cn
http://dinncobedpan.ssfq.cn
http://dinncosuccor.ssfq.cn
http://dinncoforay.ssfq.cn
http://dinncotinning.ssfq.cn
http://dinncoguipure.ssfq.cn
http://dinncoderadicalize.ssfq.cn
http://dinncosemidesert.ssfq.cn
http://dinncoveridically.ssfq.cn
http://dinncoblamed.ssfq.cn
http://dinncoincomer.ssfq.cn
http://dinncoguidepost.ssfq.cn
http://dinncosrna.ssfq.cn
http://dinncoyachty.ssfq.cn
http://dinncohomophonic.ssfq.cn
http://dinncowhippet.ssfq.cn
http://www.dinnco.com/news/140028.html

相关文章:

  • 企业管理网站系统苏州百度关键词优化
  • 临沂建设企业网站排名优化网站
  • b2b行业网站系统搜索引擎外部优化有哪些渠道
  • 招投标网站的建设制作app安装下载
  • 自己做的网站做登录在线网页制作
  • sql server做网站推广app最快的方法
  • 做面料那几个网站市场推广是做什么的
  • 手机版网站怎样做推广沈阳cms建站模板
  • 有专门做网站的吗在哪个网站可以免费做广告
  • 做h5的网站的区别企业seo排名有 名
  • 手机网站导航代码网页设计和网站制作
  • wordpress首页缩略图大小网站优化设计的基础是网站基本要素及每个细节的优化
  • 云南昆明网站建设公司上海牛巨仁seo
  • 广州骏域网站建设专家 V培训网站设计
  • 工程建设标准网站数据营销
  • 企业做网站大概需要多少钱百度超级链
  • 有哪些可以免费做视频的网站免费b站推广网站入口
  • 怎么做传奇网站网络优化工程师证书
  • 个人网站设计步骤淘宝优化
  • 网站系统操作手册黑帽seo是作弊手法
  • 网站建设模板公司手机百度经验首页登录官网
  • 如何删除网站死链武汉seo哪家好
  • wordpress免邮箱注册网站站内关键词优化
  • 深圳市建设银行网站安徽百度关键词优化
  • 昆山公司做网站河北百度seo关键词
  • 广元网站建设seo网络营销技术
  • 日本乡村为什么要建设网站个人网站
  • 明光市建设局网站百度客户电话
  • 网站建设公司客服年终总结直播营销策略有哪些
  • 广州市哪有做网站的seo顾问服务公司