四大组件_Activity_2.通过显式意图启动Activity、跳转第三方应用

本文介绍了Android开发中如何通过显式意图启动Activity进行应用内跳转,并演示了一个账户登录的demo。内容包括XML布局文件、MainActivity和SecondActivity的实现,以及如何显式启动第三方应用,如浏览器。详细讲解了setClassName和ComponentName的使用,以及获取包名和Activity名称的方法。
摘要由CSDN通过智能技术生成

如果一个Application只有一个Activity的话,Application能创造的价值可就比现在少很多了。我们需要Activity之间能够灵活的跳转,除了跳转,它能够在不同的Activity之间传送数据才算意思。
今天我们来写一个活动跳转的demo(账户登录),并了解一下显式意图启动Activity

  • 展示结果(不会上传动态图)
    在这里插入图片描述
    在这里插入图片描述

  • 显式启动Activity

  • 当前Activity

Intent intent = new Intent(MainActivity.this,SecondActivity.class);//参数:当前上下文、要跳转活动的字节码文件
                intent.putExtra("account",accountText);//数据传输
                intent.putExtra("password",passwordText);
                startActivity(intent);//启动Activity
  • 跳转Activity方
		Intent intent = getIntent();//响应
        account = intent.getStringExtra("account");//接收数据
        password = intent.getStringExtra("password");
  • 来具体看看这个demo
    • xml布局文件(activity_main)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <TextView
        android:layout_marginTop="20dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="账号"/>
    <EditText
        android:id="@+id/account_edit"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="密码"/>
    <EditText
        android:id="@+id/password_edit"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPassword"/>
    <Button
        android:id="@+id/sign_in_button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="立即登录"/>

<
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值