惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Security Archives - TechRepublic
MongoDB | Blog
MongoDB | Blog
量子位
博客园 - 叶小钗
罗磊的独立博客
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Hacker News: Ask HN
Hacker News: Ask HN
MyScale Blog
MyScale Blog
GbyAI
GbyAI
Help Net Security
Help Net Security
Y
Y Combinator Blog
Engineering at Meta
Engineering at Meta
Hacker News - Newest:
Hacker News - Newest: "LLM"
Latest news
Latest news
H
Hacker News: Front Page
Blog — PlanetScale
Blog — PlanetScale
雷峰网
雷峰网
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
C
CXSECURITY Database RSS Feed - CXSecurity.com
Scott Helme
Scott Helme
S
Schneier on Security
博客园 - 司徒正美
Hugging Face - Blog
Hugging Face - Blog
S
Security @ Cisco Blogs
Recorded Future
Recorded Future
S
Securelist
博客园 - Franky
Application and Cybersecurity Blog
Application and Cybersecurity Blog
A
About on SuperTechFans
N
News and Events Feed by Topic
AI
AI
T
Tenable Blog
N
News | PayPal Newsroom
C
Cybersecurity and Infrastructure Security Agency CISA
V
V2EX - 技术
T
Threat Research - Cisco Blogs
Cisco Talos Blog
Cisco Talos Blog
L
LINUX DO - 热门话题
N
Netflix TechBlog - Medium
S
SegmentFault 最新的问题
T
The Blog of Author Tim Ferriss
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Google Online Security Blog
Google Online Security Blog
S
Security Affairs
Webroot Blog
Webroot Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
博客园 - 三生石上(FineUI控件)
C
Comments on: Blog
G
GRAHAM CLULEY

博客园 - Rainbow

正向代理与反向代理(转) Java equals()和hashCode()的作用 java 内存模型 java 面向对象 java 集合 java string java 数据类型 Java 笔记 字符编码详解及由来(UNICODE,UTF-8,GBK)[转帖] C# 值类型和引用类型 说明 Android drawable文件夹含义 Android Button 单击事件 Android TextView setText 使用 转一篇博文 Java中==和equals的区别 FTP 链接上,但是列不出目录 出现:425 Can't open data connection CentOS常用命令 CentOS5.6 python2.4.3升级到2.7.2 yum命令全集详解
Android开发中插入新的Activity
Rainbow · 2011-11-03 · via 博客园 - Rainbow

2011-11-03 18:42  Rainbow  阅读(617)  评论()    收藏  举报

一个Activity就相当于程序的一页,如果想要跳转到新的一页,就必须插入新的Activity。
  插入新的Activity有三步骤:
  1、建立新的Activity程序代码,这里以”new.class”为例
  2、在AndroidManifest.xml中添加新Activity的描述
  3、在原有Activity中调用启动新的Activity

  下面一步一步来,首先建立新的Activity程序代码:
  在Eclipse左侧的Package Explorer中的src下的package上点右键,New一个Class。有一点要注意,在弹出的对话框中,Superclass要选择Activity,Name必须大写(这是JAVA的规定,必须这样,否则无法建立)

  在新建的Name.class里插入代码:

  public class Name extends Activity {
   @Override
   protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.new);
   }
  }

  然后建立相应的描述UI的xml文件,格式复制原有main.xml的格式即可,根据上面的代码(R.layout.new),这个xml文件名应该为new.xml。

  接下来第二步,在AndroidManifest.xml中添加新Activity的描述
  打开AndroidManifest.xml,切换到Application页面,在Application Nodes里,列出了这个程序目前所有的Activity(当然不包括我们现在要添加的),点右边的Add,如图:

  点击OK,打开AndroidManifest.xml,加入代码

  <activity android:name="Name"></activity>

  然后是在原有Activity中调用启动新的Activity

  Intent intent=new Intent();
  intent.setClass(Test.this,Name.class);//当前的Activity为Test,目标Activity为Name
  //从下面这行开始是将数据传给新的Activity,如果不传数据,只是简单的跳转,这几行代码请注释掉
  Bundle bundle=new Bundle();
  bundle.putString("key1","value1");//key1为名,value1为值
  bundle.putString("key2","value2");
  intent.putExtras(bundle);
  //传数据结束
  startActivity(intent);

  到这里,新的Activity就被制调用了,如果刚才在原Activity中传送了数据,用下面的代码可以在新的Activity中获取到。

  Bundle bundle=this.getIntent().getExtras();
  String s1=bundle.getString("key1");
  String s2=bundle.getString("key2");