Intent创建Activity
1,布局
<?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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.administrator.app.MainActivity"> <Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/open"
android:text="open"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tv_show"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="close"
android:id="@+id/close"/> </LinearLayout>
2.逻辑
package com.example.administrator.app; import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button; public class MainActivity extends AppCompatActivity {
private Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn=(Button)findViewById(R.id.open);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent= new Intent(MainActivity.this,SActivity.class);
intent.putExtra("info","title");
startActivity(intent); }
});
}
}
package com.example.administrator.app; import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView; /**
* Created by Administrator on 2018/5/22.
*/
public class SActivity extends Activity {
private Button btn;
private TextView tv_show; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.slayout);
btn=(Button)findViewById(R.id.close);
tv_show=(TextView)findViewById(R.id.tv_show);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { finish();
}
});
Intent intent=getIntent();
tv_show.setText(intent.getStringExtra("info"));
}
}
3,配置
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.administrator.app"> <application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SActivity"></activity>
</application> </manifest>
4,效果图


Intent创建Activity的更多相关文章
- Intent和Activity知识点总结
1.Intent的跳转传值2.Intent的隐式启动(用于不同应用中)与显示启动(同一应用中)3.Activity的生命周期 void onCreate()——Activity已经被创建完毕,创 ...
- 【Android进阶】为什么要创建Activity基类以及Activity基类中一般有哪些方法
现在也算是刚刚基本完成了自己的第一个商业项目,在开发的过程中,参考了不少人的代码风格,然而随着工作经验的积累,终于开始慢慢的了解到抽象思想在面向对象编程中的重要性,这一篇简单的介绍一下我的一点收获. ...
- 【Android先进】我们为什么要创建Activity基类Activity什么是一般的基类方法
今天,它可以被视为只是基本完成了其首个商业项目,在发展过程中,风格,然而随着工作经验的积累.最终開始慢慢的了解到抽象思想在面向对象编程中的重要性,这一篇简单的介绍一下我的一点收获. 首先,在如今的项目 ...
- 使用Intent创建Tab页面
前面已经介绍了如何使用TabActivity来创建Activity布局,前面添加Tab页面使用了TabHost.TabSpec如下方法. setContent(int viewId):直接将指定Vie ...
- Android学习笔记三:用Intent串联activity
转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/7513399.html 一:Intent Intent可以理解为 意图. 我们可以通过创建intent实例来定义 ...
- Android(java)学习笔记73:Intent启动Activity
1. Intent启动Activity案例 (1)首先是main.xml和other.xml文件如下: main.xml文件: <?xml version="1.0" enc ...
- 从0系统学Android-2.3使用 Intent 在 Activity 之间穿梭
2.3 使用 Intent 在 Activity 之间穿梭 在上一节中我们已经学会了如何创建一个 Activity 了.对于一个应用程序来说,肯定不可能只有一个 Activity.下面就来学习多个 A ...
- Intent实现Activity组件之间的通信
今天讲解的是使用Intent实现Activity组件之间的通信. 一. 使用Intent显式启动Activity,Activity1àActivity2 1. ...
- 创建Activity
创建Activity 创建 Activity 分为3个步骤: 1.创建一个扩展子Activity的class 2.创建一个Layout 3.在 AndroidMainfest 中 配置这个Activ ...
随机推荐
- [C++] 拓展属性
inline函数 函数重载 占位参数和默认参数 /*__________________________________________________________________ 背景: C++ ...
- hadoop 客户的的使用
${HADOOP_HOME}/bin/hadoop job Usage: JobClient <command> <args> [-submit <job-file> ...
- node + express + iis + iisnode + urlrewrite搭建站点
前提条件:安装iis的电脑 准备条件: 1.下载iisnode 地址https://github.com/tjanczuk/iisnode/wiki/iisnode-releases 安装 2.下载 ...
- 第六章 系统配置:DHCP和自动配置
系统配置:DHCP和自动配置 写在开头:今天和导师见了个面,抛给我一堆材料以及论文,感觉自己学业更加繁重.有些知识现阶段我可能没办法掌握,但是至少在我需要进一步理解它的时候,要知道在哪个地方能够找到. ...
- Python中的返回函数与闭包
返回函数,顾名思义,就是高阶函数可以把函数作为return值返回.与闭包的关系是:闭包需要以返回函数的形式实现. 一. 返回函数 比如我们有一个求和函数: >>> def calc_ ...
- PHP error_reporting
E_ERROR 致命错误,脚本执行中断,就是脚本中有不可识别的东西出现 E_WARNING 部分代码出错,但不影响整体运行 E_PARSE 字符.变量或结束的地方写规范有误 ...
- swf自动播放时如何全屏全部显示
在QQ Show里面看到一个很可爱的挂件,很想把它弄下来.弄下来的方法很简单,直接去网页缓存文件里面找.找到了之后,按下面的方法插入到网页中: 1 <object height="10 ...
- Codeforces Round #324 (Div. 2) B
B. Kolya and Tanya time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- bzoj3561 莫比乌斯反演
DZY Loves Math VI Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 518 Solved: 344[Submit][Status][D ...
- java集合类深入分析之PriorityQueue(二)
PriorityQueue介绍 在平时的编程工作中似乎很少碰到PriorityQueue(优先队列) ,故很多人一开始看到优先队列的时候还会有点迷惑.优先队列本质上就是一个最小堆.前面一篇文章介绍了堆 ...