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. 最短路变短了 (思维+反向djstrea)

    题解:设有一条边x->y,数组dis1[i]表示从1到i的最短距离,dis2[i]表示从n到i的最短距离. 1 如果说将x->y反向之前没有经过x->y,但是反向后我经过了x,y说明 ...

  2. C - Trailing Zeroes (III) 二分

    You task is to find minimal natural number N, so that N! contains exactly Q zeroes on the trail in d ...

  3. springboot集成JdbcTemplate+druid

    application.yml datasource: username: root password: root url: jdbc:mysql://localhost:3306/early_war ...

  4. CKEditor与定制

    一 开始使用 官网 基本示例: 搭建服务器(这里使用apache) 下载standard的ckeditor解压放在apache的htdocs的目录下 在htdoc下面新建index.html,写入代码 ...

  5. 1. jquery插件手机

    1. http://jqtjs.com/preview/demos/main/index.html#home2. jquery weUI ===== 插件:https://blog.csdn.net/ ...

  6. PHP代码审计理解(一)----Metinfo5.0变量覆盖

    0x01 漏洞简介 这个漏洞是metinfo5.0变量覆盖漏洞,并且需要结合文件包含.我使用的cms版本是5.3,事实上已经修复了这个漏洞(5.0的cms源码已经找不到了哈),但是我们可以借他来学习理 ...

  7. jmeter并发时生成唯一变量

    vars.put("partnerOrderId","ZS"+Thread.currentThread().getId()+System.currentTime ...

  8. redis: Set集合类型(五)

    Set里面的值是不能重复的 Set设置值(头部):sadd myset hello Set获取值:smembers myset 检查Set是否包含某个元素:sismember myset hello ...

  9. pytorch 手写数字识别项目 增量式训练

    dataset.py ''' 准备数据集 ''' import torch from torch.utils.data import DataLoader from torchvision.datas ...

  10. synchronized 作为悲观锁,锁住了什么?

    继续来认识 synchronized,上篇文章加不加 synchronized 有什么区别?我们了解了 synchronized 是在多线程并发竞争同一资源的时候使用,这一篇我们来了解,synchro ...