iis服务器助手广告广告
返回顶部
首页 > 资讯 > 移动开发 >Android实现页面跳转的全过程记录
  • 550
分享到

Android实现页面跳转的全过程记录

2024-04-02 19:04:59 550人浏览 独家记忆
摘要

目录1、启动新Activty1.1、功能分析1.2、开发视图布局1.3、按钮事件响应1.4、测试结果2、启动其他App2.1、功能分析2.2、开发视图布局2.3、按钮事件响应2.4、

1、启动新Activty

1.1、功能分析

  • App功能
    • 在第一个Activity输入消息
    • 点击第一个Activity的发送按钮
    • 发送消息到第二个Activity
    • 第二个Activity显示收到的消息
  • App结构(2个Activity+2个Layout) :
    • 打开App时,启动CreateMessageActivty
      加载activity_create_message.xml作为布局
    • 用户点击按钮启动ReceiveMessageActivty
      加载activity _receive_message.xml作为布局

1.2、开发视图布局

activity_create_message.xml


<?xml version="1.0" encoding="utf-8"?>
<Androidx.constraintlayout.widget.ConstraintLayout xmlns:android="Http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".CreateMessageActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <EditText
            android:id="@+id/input"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:hint="@string/hint"
            android:inputType="textPersonName"
            android:textSize="30sp"/>

        <Button
            android:id="@+id/button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:onClick="onSendMessage"
            android:text="@string/send"
            android:textSize="30sp"
            />

    </LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

activity _receive_message.xml


<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_constraintRight_toRightOf="parent"
    tools:context=".ReceiveMessageActivity">

    <TextView
        android:id="@+id/output"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="2nd Activity"
        android:textSize="34sp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constr

string.xml


<resources>
    <string name="app_name">Messager</string>
    <string name="send">Send Message</string>
    <string name="hint">Enter a message</string>
    <string name="choser">Send Message via ...</string>
</resources>

1.3、按钮事件响应

CreateMessageActivty类:发送消息


public class CreateMessageActivity extends AppCompatActivity {

    //定义常量,作为消息的key
    public static final String MESSAGE_KEY="szst.it.ping.messager";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_create_message);
    }

    public void onSendMessage(View Button){
        //获得编辑框引用
        EditText editText = findViewById(R.id.input);
        //取出编辑框文字
        String message = editText.getText().toString();

        //Intent是Android中的信使,新建Intent打开,设置收件Activity为ReceiveMessageActivity
        Intent intent = new Intent(this,ReceiveMessageActivity.class) ;
        //在intent中附加消息
        intent.putExtra(MESSAGE_KEY,message);
        //向Android发出请求
        startActivity(intent);

    }
}

ReceiveMessageActivty类:接收消息


public class ReceiveMessageActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_receive_message);

        //获得intent的引用
        Intent intent = getIntent();

        //根据key取出value
        String message = intent.getStringExtra(CreateMessageActivity.MESSAGE_KEY);

        //获得文本框内容,设置文字
        TextView textView = findViewById(R.id.output);
        textView.setText(message);
    }
}

1.4、测试结果

启动界面

输入消息“123”并点击按钮发送,接收界面如下

 

2、启动其他App

2.1、功能分析

  • App功能
    • 在第一个Activity输入消息
    • 点击第一个Activity的发送按钮
    • 发送消息到其他App
    • 其他App显示收到的消息
  • App结构(1个Activity+1个Layout) :
    • 打开App时,启动CreateMessageActivty
      加载activity_create_message.xml作为布局
    • 用户点击按钮启动选择启动满足条件的App

2.2、开发视图布局

  • activity_create_message.xml
    • 同1.2中的activity_create_message.xml

2.3、按钮事件响应

CreateMessageActivty类:发送消息


public class CreateMessageActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_create_message);
    }

    public void onSendMessage(View Button){
        //获得编辑框引用
        EditText editText = findViewById(R.id.input);
        //取出编辑框文字
        String message = editText.getText().toString();

        //使用new Intent(Intent.ACTION_SEND)替换new Intent(this, ReceiveMessageActivity.class),不知道其它App中的类名
        Intent intent = new Intent(Intent.ACTION_SEND);
        //设置消息类型为纯文本,系统不会对消息进行处理
        intent.setType("text/plain");
        //向Intent添加附加信息
        intent.putExtra(Intent.EXTRA_TEXT,message);

        //自定义选择对话框
        String chooserTitle = getString(R.string.choser);
        Intent chosenIntent = Intent.createChooser(intent, chooserTitle);

        startActivity(chosenIntent) ;
    }
}

2.4、测试结果

启动界面同1.4

输入消息“123”并点击按钮发送,选择要发送的app(Messaging)

发送附加消息到111

发送成功

总结

到此这篇关于Android实现页面跳的文章就介绍到这了,更多相关Android实现页面跳转内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

--结束END--

本文标题: Android实现页面跳转的全过程记录

本文链接: https://www.lsjlt.com/news/154617.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Android实现页面跳转的全过程记录
    目录1、启动新Activty1.1、功能分析1.2、开发视图布局1.3、按钮事件响应1.4、测试结果2、启动其他App2.1、功能分析2.2、开发视图布局2.3、按钮事件响应2.4、...
    99+
    2022-11-12
  • react 怎么实现页面跳转不记录
    本教程操作环境:Windows10系统、react18.0.0版、Dell G3电脑。react 怎么实现页面跳转不记录?React-router:页面跳转并清除当前页的历史记录有如下情况:用户打开激活链接;用户完成激活过程后,系统会将其移...
    99+
    2023-05-14
    React
  • react如何实现页面跳转不记录
    今天小编给大家分享一下react如何实现页面跳转不记录的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。react实现页面跳转不...
    99+
    2023-07-04
  • Android实现页面跳转
    本文实例为大家分享了Android实现页面跳转的具体代码,供大家参考,具体内容如下 一. Android实现页面跳转有两种方式,一种为.MainActivity跳转;第二种是Rela...
    99+
    2022-11-13
  • Android 实现页面跳转
    android使用Intent来实现页面跳转,Intent通过startActivity(Intent intent)或startActivityForResult(Intent intent,int resquestCode)方法来启动A...
    99+
    2023-05-30
    android 页面 跳转
  • Android Studio怎么实现注册页面跳转登录页面
    今天小编给大家分享一下Android Studio怎么实现注册页面跳转登录页面的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了...
    99+
    2023-06-30
  • android如何实现页面跳转
    Android中实现页面跳转主要有两种方式:隐式跳转和显式跳转。1. 隐式跳转:隐式跳转是指通过指定Intent的Action来进行...
    99+
    2023-08-19
    android
  • Android Studio 点击按钮实现页面跳转、网页跳转
    页面跳转、网页跳转 1)页面跳转 Btn1=findViewById(R.id.btn_1); Btn1.setOnClickListener(new View.OnClickListe...
    99+
    2023-09-17
    android studio android kotlin
  • android studio实现简单的页面跳转
    运用intent组件实现简单的跳转 主页面 Button button1,button2,button3; //xml文件定义的id @Override protected void onCreate(Bundle savedI...
    99+
    2023-10-11
    android studio android java
  • vue实现token过期自动跳转到登录页面
    这几天项目提测,测试给我提了个bug,说token过期,路由应该自动跳转到登陆页面,让用户重新登录。先说下一些前置条件, 1:我公司的token时效在生产环境设置为一个小时,当to...
    99+
    2022-11-12
  • react.js实现页面登录跳转示例
    1,页面目录信息: 2,从index.js导入路由信息BasicRoute.js,然后BasicRoute.js中存储App.js和StatisticsInformation.js...
    99+
    2023-01-31
    react.js登录跳转 react.js页面跳转
  • AndroidStudio实现注册页面跳转登录页面的创建
    本文是用来介绍Android Studio创建注册页面跳转登录页面的界面设计以及跳转功能地实现,完整结构见文章结尾。 用户注册界面 <xml version="1.0" en...
    99+
    2022-11-13
  • Android Studio实现简单的页面跳转(简单教程)
                     项目实现:(实现Android Studio 基本有两种实现方式:一种为.MainActivity跳转;第二种是Relatelayout布局跳转。                   这里着重介绍第一种:(...
    99+
    2023-09-21
    android studio android ide java androidx
  • Android Studio实现简单页面跳转的详细教程
    目录首先设置Activity_main的文件设置:另一个页面布局的设计: 代码设计:然后是第一个JAVA代码的设计:另一个跳转文件所需要的页面JAVA代码:最后一点着重说明...
    99+
    2023-01-11
    android studio页面跳转代码 androidstudio页面跳转不了 androidstudio点击按钮跳转页面
  • vue单页面改造多页面应用的全过程记录
    前言 单页面和多页面的区别这里就不细说了。我司业务适合多页面,许多小应用都是通过iframe整体嵌入的形式。 如果项目过于庞大,就会有很不好的体验问题。拆分多个项目的话,又会有额外的...
    99+
    2022-11-13
  • android studio实现页面跳转(点击按钮)
    在已经创建的java文件MainActivity(点击app,点击java)下里面编写  package com.example.myapplication1120;import android.content.Intent;import ...
    99+
    2023-10-09
    android studio android ide
  • JavaFx实现登录成功跳转到程序主页面
    本文实例为大家分享了JavaFx实现登录成功跳转到程序主页面的具体代码,供大家参考,具体内容如下 1、需求 登录页面在输入账号密码之后,验证账号密码时候正确,正确就跳转到应用程序的首...
    99+
    2022-11-13
  • android怎么实现点击按钮跳转页面
    Android中实现点击按钮跳转页面可以通过以下步骤实现:1. 在XML布局文件中定义一个按钮组件,例如:```xml```2. 在Java代码中获取按钮组件,并设置点击事件监听器,例如:```javaButton button = f...
    99+
    2023-08-11
    android
  • react跳转前记住页面状态怎么实现
    本教程操作环境:Windows10系统、react18.0.0版、Dell G3电脑。react跳转前记住页面状态怎么实现?React 页面返回保留上次状态需求页面A跳转到页面B然后再返回页面A,页面A要还原离开前的状态;页面A和页面B有多...
    99+
    2023-05-14
    跳转 React
  • react如何实现跳转前记住页面状态
    这篇文章主要介绍了react如何实现跳转前记住页面状态的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇react如何实现跳转前记住页面状态文章都会有所收获,下面我们一起来看看吧。react实现跳转前记住页面状态的...
    99+
    2023-07-04
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作