首页 > 其他分享 >aandroid studio 通过intent向另一个界面传输信息

aandroid studio 通过intent向另一个界面传输信息

时间:2024-06-06 20:45:50浏览次数:13  
标签:layout name parent app studio aandroid intent android

基本流程和上一篇一样

地址:  https://www.cnblogs.com/yansans/p/18235968

 

只是再最后加了一句代码

intent.putExtra("name",name.getText().toString());

这句代码用键值对比较好理解,是将从前端传递来的name的值命名为“name”并传递给MainActivity2

 

MainActivity2的后端代码是

package zy.test1;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity2 extends AppCompatActivity {

//控件
private TextView textView = null;

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

Init();
}

private void Init() {
textView = findViewById(R.id.zhanshi);

Intent intent = getIntent();
String name = intent.getStringExtra("name");

textView.setText("用户为:" + name);
}

}

其中最主要的是

Intent intent = getIntent();
String name = intent.getStringExtra("name");
textView.setText("用户为:" + name);

这里的几句

意思是接收上一个界面传来的名为name的值,并存储MainActivity2的前端界面

MainActivity2的前端代码

<?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=".MainActivity">


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 嗨嗨嗨!!! "
android:textSize="35sp"
app:layout_constraintBottom_toTopOf="@+id/zhanshi"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.444"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.512" />

<TextView
android:id="@+id/zhanshi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 用户"
android:textSize="35sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.135"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.416" />

</androidx.constraintlayout.widget.ConstraintLayout>

 

结果

 

标签:layout,name,parent,app,studio,aandroid,intent,android
From: https://www.cnblogs.com/yansans/p/18235987

相关文章

  • Android studio后端接收数据步骤
    最近记性越来越差,简单的实验居然磨了我三个小时只好把详细步骤放出来,防止再忘记 前端<?xmlversion="1.0"encoding="utf-8"?><androidx.constraintlayout.widget.ConstraintLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="htt......
  • 使用Visual Studio分析.NET Dump
    前言内存泄漏和高CPU使用率是在日常开发中经常遇到的问题,它们可能会导致应用程序性能下降甚至崩溃。今天我们来讲讲如何使用VisualStudio2022分析.NETDump,快速找到程序内存泄漏问题。什么是Dump文件?Dump文件又叫内存转储文件或者叫内存快照文件。用于存储程序运行时的状态......
  • Android课程设计课题题目推荐(安卓期末大作业,毕业设计,Androidstudio)
    博主介绍:本人专注于Android/java/数据库/微信小程序技术领域的开发,以及有好几年的计算机毕业设计方面的实战开发经验和技术积累;尤其是在安卓(Android)的app的开发和微信小程序的开发,很是熟悉和了解;本人也是多年的Android开发人员;希望我发布的此篇文件可以帮助到您;......
  • 01《android studio开发实战(第三版)》阅读笔记
    第一章:初识AndroidStudio本章介绍AndroidStudio的基本概念和安装步骤,帮助读者快速搭建开发环境。了解AndroidStudio的发展历史和其在Android开发中的地位。安装和配置:详细说明了如何在Windows、Mac和Linux系统上安装AndroidStudio,并进行必要的配置。创建第一个项目:通过......
  • VSCode(Visual Studio Code) C/C++ 开发环境 | MinGW无需输入代码 — 99.99%成功率(超详
    VisualStudioCodeC++六一马不停蹄更新中……参考资料:visualstudio|cppuninstall|vscode———————————————————————————————————————————————卸载VSCode【如没下跳转】-先下载下准备zip:MinGW32.zipMinGW真......
  • Android Studio使用ADB远程调试(真机)(通过无线调试)
    准备工作1)设备:笔记本电脑、安卓手机2)设备连接相同网络(如:同个WIFI)3)手机开启开发者模块、USB调试、USB安装ps:本人安卓手机是红米手机,开启开发者模式可参考:https://baijiahao.baidu.com/s?id=1758792460891751075&wfr=spider&for=pc操作步骤1)打开AndroidStudio,通过File->Proje......
  • visual studio 插件开发 - 项目介绍
    1.项目结构创建步骤:1.创建名为xxxx的VSIX项目。可以通过搜索“vsix”在“新建项目”对话框中找到VSIX项目模板。2.项目打开时,添加名为FirstCommand的自定义命令项模板。创建好一个vsix项目后最简单的结构:XXXXPackage.cs称为Package类。VisualStudio调用......
  • visual studio 插件开发 - 概述
    VisualStudio插件开发1.插件的概述1.1VisualStudio扩展执行哪些类型的操作?对VisualStudio中不包含的语言的支持,并提供语法着色、IntelliSense和编译器和调试支持。使用更多模板、代码重构、新对话框或工具窗口扩展核心IDE体验的生产力工具。特定于域的设计器,适......
  • ASP.NET Web应用程序升级最新的MSBuild格式后,Visual Studio 2022中如何调试?
    摘要把ASP.NET的Web应用程序,Project文件从<ProjectToolsVersion="12.0"DefaultTargets="Build"xmlns="http://schemas.microsoft.com/developer/msbuild/2003">改为<ProjectSdk="Microsoft.NET.Sdk.Web">之后,升级成了最新的格式之后,如......
  • 简单4步,带你用华为云MetaStudio制作数字人短片
    本文分享自华为云社区《使用MetaStudio生产线四步制作数字人视频》,作者:yd_298097624。随着AIGC新技术尤其是大模型技术的发展,音视频行业、数字内容生产行业正在经历这从生产方式和生产效率上的一个巨大变化。预测到2030年有AI大模型生成的数字内容比例将高达90%,包括通过AIGC来生......