1.Intent显式跳转页面

val button5 = findViewById<Button>(R.id.mButton5)

button5.setOnClickListener {
val intent = Intent()
intent.setClass(this, ThirdActivity::class.java)
startActivity(intent)
}

跳转方式一

intent.setClass(this, ThirdActivity::class.java)

// 获取class是使用::反射

跳转方式二

intent.setClass(this, ThirdActivity().javaClass)

2.Intent隐式跳转调用系统拨号

val button6 = findViewById<Button>(R.id.mButton6)

button6.setOnClickListener {
val intent = Intent(Intent.ACTION_DIAL)
val url = Uri.parse("tel:10086")
intent.data = url
startActivity(intent)
}

3.Intent跳转页面并向下一页传值

val button7 = findViewById<Button>(R.id.mButton7)

override fun onClick(v: View?) {
when (v?.id) {
R.id.mButton1 ->
Toast.makeText(this, "java", Toast.LENGTH_LONG).show()
R.id.mButton2 ->
Toast.makeText(this, "java", Toast.LENGTH_LONG).show()
R.id.mButton7 -> {
val intent = Intent(this@MainActivity, GetIntentData::class.java)
val bundle = Bundle()
bundle.putString("text", "Kotlin练习")
intent.putExtras(bundle)
startActivity(intent)
}
}
}

注意 使用when 当有多行代码时使用“{ }”括起来

接收Activity页面代码

private fun initView() {
val bundle = this.intent.extras
val str = bundle?.get("text").toString()
val mTvText = findViewById<TextView>(R.id.mTvText)
mTvText.text = str
}
mTvText.text = str 相当于java中 mTvText.setText(str)

以上

第一行Kotlin系列(二)Intent隐式显式跳转及向下传值的更多相关文章

  1. Activity组件(二):通过显式意图和隐式意图来跳转至第三方应用

    一.显式意图来跳转到第三方应用 /** * 这个方法会在点击按钮的时候执行 * @param view */ public void skip2Browser(View view){ Log.d(TA ...

  2. 第一行Kotlin系列(三)Intent 向上一页返回数据onActivityResult的使用

    1.MainActivity.kt跳转处理 声明全局的按钮对象 private lateinit var button8: Button 实例化按钮对象 button8 = findViewById( ...

  3. 第一行Kotlin系列(一)kotlin按钮点击事件

    按钮findViewBuId <Button android:id="@+id/mButton4" android:layout_width="wrap_conte ...

  4. Activity跳转显式方法及隐式方法

    1 public class AActivity extends AppCompatActivity { 2 private Button btnJump; 3 @Override 4 protect ...

  5. GC与显式内存管理

    C++复兴的话题至今已被鼓吹两年有余,Herb Sutter和Bjarne Stroustrup等大牛们也为C++带来了大步伐的革新.然而,从这两年的效果而言,C++的复兴并没有发生.一方面随着世界经 ...

  6. (转载)Android理解:显式和隐式Intent

    Intent分两种:显式(Explicit intent)和隐式(Implicit intent). 一.显式(设置Component) 显式,即直接指定需要打开的activity对应的类. 以下多种 ...

  7. android intent 隐式意图和显示意图(activity跳转)

    android中的意图有显示意图和隐式意图两种, 显示意图要求必须知道被激活组件的包和class 隐式意图只需要知道跳转activity的动作和数据,就可以激活对应的组件 A 主activity  B ...

  8. [转]Activity详解 Intent显式跳转和隐式跳转

    Activity 生命周期             显式 Intent 调用          1     //创建一个显式的 Intent 对象(方法一:在构造函数中指定)  2      Inte ...

  9. (三)使用Intent在活动中穿梭:显式和隐式Intent

    一.显式Intent @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstan ...

随机推荐

  1. Spring5:Java Config

    @Configuration @Bean @ComponentScan @ImportResource 使用Java的方式配置spring,完全不使用spring配置文件,交给java来做! 两个注解 ...

  2. 尝试用Vue.js开发网页小游戏的过程

    准备 首先去官方下载并安装VSCODE,下载地址 https://code.visualstudio.com/.安装后打开会发现是英文版的,需要去安装插件来汉化.具体是在扩展插件搜索chinese,选 ...

  3. shift count is too large

    STM8S是8 bit单片机在STM8S中 unsigned long是32位, unsigned short和unsigned int都是16位,unsigned char是8位. 以以下代码编译时 ...

  4. tp5.0看点

    前置操作:操作一些其他动作,例如要操作其他表格的数据啊,操作之前要有什么动作为前提或者要注意的动作. 模型事件:操作数据,例如照片的上传修改和删除. 两者的区别在于“前置操作”是动作,而“模型事件”只 ...

  5. qt 鼠标拖动窗口 跳动 解决

    因为获取当前的位置,似乎没有把标题栏的高度记进去. 所以移动前,得考虑到标题栏的高度. 用以下方式获取标题栏高度: QApplication::style()->pixelMetric(QSty ...

  6. 【Inno Setup】Pascal 脚本 ---- 事件函数

    转载 事件函数 Inno Setup支持以下函数和过程. 1. [安装初始化]该函数在安装程序初始化时调用,返回False 将中断安装,True则继续安装,测试代码如下: function Initi ...

  7. Django新手十个开发指导

    下面是关于Django新手开发中的一些建议,大家可以参考一下~~ 1,不要将项目名称包含在引用代码里 比如你创建了一个名为"project"的项目,包含一个名为"app& ...

  8. 怎么在java中关闭一个thread

    怎么在java中关闭一个thread 我们经常需要在java中用到thread,我们知道thread有一个start()方法可以开启一个线程.那么怎么关闭这个线程呢? 有人会说可以用Thread.st ...

  9. Excel中的clean函数

    纯属note. 之前经常用excel处理数据的时候,对长文本或网站上拉取的值都会用clean函数清除一些我们肉眼看不到的非打印字符. Excel官方介绍:clean 删除文本中的所有非打印字符. 此次 ...

  10. 解决material UI中弹窗(dialog、popover等)内容被遮挡问题

    在material ui中有几种弹出层,比如:dialog.popover等,这些弹出层都会遇到的一个公共问题是: 假如弹出层中的内容变化了,弹出层的位置并不会重新定位. 这样,假如一开始弹出层定位在 ...