3、Android中Activity的跳转
Android 跳转 Activity
2023-09-11 14:14:42 时间
1、创建project
file->new->android application 依次填入应用名称、project名、包名
在project文件夹下找到src/com.example.helloworld MainActivity.java
2、加入代码
package com.example.helloworld; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class MainActivity extends Activity { private Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); this.button = (Button) this.findViewById(R.id.button1); this.button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(); intent.setClass(MainActivity.this, IntentActivity.class); intent.putExtra("name", "Hello World"); startActivity(intent); } }); } }
在加入代码之前,先在res/layout/activity_main.xml中,拖拽一个Button控件上去。此时会自己主动在activity_main.xml中生成Button的信息。注意id值,假设使用此Button,实用
3、加入跳转Activity
1、右击src/com.example.helloworld,new->class。在name处填写IntentActivity,不用加java就可以
2、加入layout。在res/layout处右击。new->android XML file,在此xml上拖拽一个TextView上去。此时在R.java中自己主动加入了TextView的地址
3、在AndroidManifest.xml中加入例如以下代码:完毕Activity的注冊
<activity android:name="com.example.helloworld.IntentActivity"> </activity>4、实现IntentActivity.java
package com.example.helloworld; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; import android.content.Intent; public class IntentActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_intent); Intent intent = getIntent(); String string = intent.getStringExtra("name"); TextView textView = new TextView(this); textView.setTextSize(40); textView.setText(string); setContentView(textView); } }
4、执行
打开模拟器或者手机,执行。
相关文章
- [Android Pro] 横竖屏切换时,禁止activity重新创建,android:configChanges="keyboardHidden|orientation" 不起作用
- [Android Pro] android 禁用和开启四大组件的方法(setComponentEnabledSetting )
- Android教程-android studio 制作.9 图片
- 浅论Android网络请求库——android-async-http
- Failed to fetch URl https://dl-ssl.google.com/android/repository/addo Android SDK更新以及ADT更新出现问题的解决办法
- Android中如何使用列表对话框
- 【Android 疑难杂症1】android.content.ActivityNotFoundException: Unable to find explicit activity class
- Android之检查网络是否可用(跳转网络设置页面)
- 《android开发艺术探索》读书笔记(十五)--Android性能优化
- macos安装android studio(Android Studio 2021.1.1)
- 转--Android中调用webservice的工具类
- android--显式跳转和隐式跳转
- Android开发者指南(26) —— Resource Types - Layout
- Android:在Fragment中使用Intent进行页面跳转
- Android车载应用开发指南2.0版,全网阅读量10k+
- android开发分享Android中外接键盘的检测的实现
- Android【报错】This class should be public (android.support.v7.internal.widget.ActionBarView.HomeView)
- android 11.0 Launcher3固定横屏(二)
- Android 9.0 延时开机动画解决首次开机黑屏和去掉android正在启动的提示框
- android 9.0 VolumeUI系统媒体音量设置为最大值80%
- android RecyclerView的滚动事件OnScrollListener详解
- Android系统的硬件驱动程序开发流程 通过 proc文件系统, devfs文件系统, C可执行程序验证驱动程序正确性
- 【Android Gradle 插件】将自定义 Gradle 插件上传到自建 Maven 仓库 ④ ( 默认生成的 pom 文件 | Maven 中的 pom 配置 | 自定义 pom 文件节点 )
- 【Android Gradle 插件】ProductFlavor 配置 ( multiDexEnabled 配置 | multiDexKeepFile | multiDexKeepProguard )
- 【Android 逆向】函数拦截 ( GOT 表拦截 与 插桩拦截 | 插桩拦截简介 | 插桩拦截涉及的 ARM 和 x86 中的跳转指令 )
- network: Android 网络推断(wifi、3G与其它)
- Android自定义View+贝赛尔曲线