付费下载
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
【移动应用开发技术】Android中怎么实现Activity跳转操作
Android中怎么实现Activity跳转操作,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。Android中提供一个叫Intent的类来实现屏幕之间的跳转,下面是一个简单的示例:在应用中增加一个Activity(名字为.ForwardTarget),这需要修改AndroidManifest.xml文件,如下:AndroidActivity跳转代码示例:<
?xml
version="1.0"
encoding="utf-8"?>
<
manifest
xmlns:android="<
A
href="/apk/res/android">/apk/res/android<
/A>"
package="com.ray.forward"
android:versionCode="1"
android:versionName="1.0">
<
application
android:icon="@drawable/icon"
android:label="@string/app_name">
<
activity
android:name=".androidForward"
android:label="@string/app_name">
<
intent-filter>
<
action
android:name="ent.action.MAIN"
/>
<
category
android:name="ent.category.LAUNCHER"
/>
<
/intent-filter>
<
/activity>
<
activity
android:name=".ForwardTarget">
<
/activity>
<
/application>
<
uses-sdk
android:minSdkVersion="3"
/>
<
/manifest>
<
?xml
version="1.0"
encoding="utf-8"?>
<
manifest
xmlns:android="/apk/res/android"
package="com.ray.forward"
android:versionCode="1"
android:versionName="1.0">
<
application
android:icon="@drawable/icon"
android:label="@string/app_name">
<
activity
android:name=".androidForward"
android:label="@string/app_name">
<
intent-filter>
<
action
android:name="ent.action.MAIN"
/>
<
category
android:name="ent.category.LAUNCHER"
/>
<
/intent-filter>
<
/activity>
<
activity
android:name=".ForwardTarget">
<
/activity>
<
/application>
<
uses-sdk
android:minSdkVersion="3"
/>
<
/manifest>
<
?xml
version="1.0"
encoding="utf-8"?>
<
manifest
xmlns:android="<
A
href="/apk/res/android">/apk/res/android<
/A>"
package="com.ray.forward"
android:versionCode="1"
android:versionName="1.0">
<
application
android:icon="@drawable/icon"
android:label="@string/app_name">
<
activity
android:name=".androidForward"
android:label="@string/app_name">
<
intent-filter>
<
action
android:name="ent.action.MAIN"
/>
<
category
android:name="ent.category.LAUNCHER"
/>
<
/intent-filter>
<
/activity>
<
activity
android:name=".ForwardTarget">
<
/activity>
<
/application>
<
uses-sdk
android:minSdkVersion="3"
/>
<
/manifest>
<
?xml
version="1.0"
encoding="utf-8"?>
<
manifest
xmlns:android="/apk/res/android"
package="com.ray.forward"
android:versionCode="1"
android:versionName="1.0">
<
application
android:icon="@drawable/icon"
android:label="@string/app_name">
<
activity
android:name=".androidForward"
android:label="@string/app_name">
<
intent-filter>
<
action
android:name="ent.action.MAIN"
/>
<
category
android:name="ent.category.LAUNCHER"
/>
<
/intent-filter>
<
/activity>
<
activity
android:name=".ForwardTarget">
<
/activity>
<
/application>
<
uses-sdk
android:minSdkVersion="3"
/>
<
/manifest>
然后在layout中的main加入一个id为leah2的按钮,另外再创建一个任意的layout(将要跳转到得layout),我取名为leah2。接下来是两个类,一个是AndroidForward,另一个是将要跳转到得ForwardTarget,AndroidActivity跳转实现的代码分别如下:AndroidForw:
package
com.ray.forward;
import
android.app.Activity;
import
android.content.Intent;
import
android.os.Bundle;
import
android.view.View;
import
android.widget.Button;
public
class
androidForward
extends
Activity
{
/**
Called
when
the
activity
is
first
created.
*/
@Override
public
void
onCreate(Bundle
savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button
btn1
=(Button)findViewById(R.id.leah2);
btn1.setOnClickListener(new
View.OnClickListener(){
@Override
public
void
onClick(View
v)
{
Intent
intent
=
new
Intent();
intent.setClass(androidForward.this,
ForwardTarget.class);
startActivity(intent);
finish();//停止当前的Activity,如果不写,则按返回键会跳转回原来的Activity
}
});
}
}
package
com.ray.forward;
import
android.app.Activity;
import
android.content.Intent;
import
android.os.Bundle;
import
android.view.View;
import
android.widget.Button;
public
class
androidForward
extends
Activity
{
/**
Called
when
the
activity
is
first
created.
*/
@Override
public
void
onCreate(Bundle
savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button
btn1
=(Button)findViewById(R.id.leah2);
btn1.setOnClickListener(new
View.OnClickListener(){
@Override
public
void
onClick(View
v)
{
Intent
intent
=
new
Intent();
intent.setClass(androidForward.this,
ForwardTarget.class);
startActivity(intent);
finish();//停止当前的Activity,如果不写,则按返回键会跳转回原来的Activity
}
});
}
}
ForwardTarget:
package
com.ray.forward;
import
android.app.Activity;
import
android.os.Bundle;
public
class
ForwardTarget
extends
Activity{
@Override
protected
void
onCreate(Bundle
savedInstanceState)
{
//
TODO
Auto-generated
method
stub
super.onCreate(savedInstanceState);
setContentView(R.layout.leah2);
}
}
AndroidForw:
package
com.ray.forward;
import
android.app.Activity;
import
android.content.Intent;
import
android.os.Bundle;
import
android.view.View;
import
android.widget.Button;
public
class
androidForward
extends
Activity
{
/**
Called
when
the
activity
is
first
created.
*/
@Override
public
void
onCreate(Bundle
savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button
btn1
=(Button)findViewById(R.id.leah2);
btn1.setOnClickListener(new
View.OnClickListener(){
@Override
public
void
onClick(View
v)
{
Intent
intent
=
new
Intent();
intent.setClass(androidForward.this,
ForwardTarget.class);
startActivity(intent);
finish();//停止当前的Activity,如果不写,则按返回键会跳转回原来的Activity
}
});
}
}
package
com.ray.forward;
import
android.app.Activity;
import
android.content.Intent;
import
android.os.Bundle;
import
android.view.View;
import
android.widget.Button;
public
class
androidForward
extends
Activity
{
/**
Called
when
the
activity
is
first
created.
*/
@Override
public
void
onCreate(Bundle
savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026湖南娄底涟源市市直事业单位公开招聘人员43人考前冲刺密卷有答案详解
- 2026江西吉安市吉水县吉阳产业发展有限公司及其子公司面向社会招聘2名工作人员考前冲刺试卷及参考答案详解
- 2026年辽宁省检验检测认证中心公开招聘高层次和急需紧缺人才7人模拟试卷附完整答案详解【历年真题】
- 2026湖北武汉德恒昌机电工程有限公司招聘模拟试卷【夺冠系列】附答案详解
- 2026吉林四平市事业单位选调17人(4号)笔试题库附答案详解【综合题】
- 2026广西兴业县城隍镇卫生院招聘编外工作人员4人的考前冲刺密卷附答案详解【B卷】
- 2026云南临沧云县零工市场招聘销售顾问2人考前冲刺密卷附完整答案详解【全优】
- 2026年永泰县卫健系统事业单位公开招聘高层次和紧缺急需专业人员备考题库及答案详解【全优】
- 2026江西鹰潭贵溪市第四中学教师招聘13人考前冲刺密卷及一套答案详解
- 2026年武宁县教师选调【120人】考前冲刺试卷附答案详解【B卷】
- 2026年嘉兴市秀洲区公开招聘劳动合同制教职工(幼儿教师、卫生保健员)24人笔试备考题库及答案详解
- 2026天津一中高一入学数学分班考试真题含答案
- 2026肉牛养殖环境承载力评估与生态平衡维护报告
- 水利水电工程单元工程施工质量检验表与验收表(SLT631.5-2025)
- 异常子宫出血护理查房的课件
- 海康威视电力行业系统解决方案
- 电动柔性堆积大门
- 云南省沧源县班洪乡翁子铅锌矿地质勘探(探矿权保留)项目环评报告
- 标致308汽车说明书
- 入库物品验收规范
- 电气安全隐患排查要点
评论
0/150
提交评论