付费下载
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
【移动应用开发技术】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 专注力培养智能改进课件
- 2026年幼儿园窗花课件
- 2026年乐高幼儿园讲课
- 2026年植物的身体幼儿园
- 2026年纪录片幼儿园
- 2026 幼儿情绪管理压力应对课件
- 2026年影像医师定期考核考试综合练习及参考答案详解【满分必刷】
- 2026年国开电大矿井运输提升(专)形考试题(得分题)及答案详解(基础+提升)
- 2026年交管12123驾照学法减分完整版试卷附答案详解(轻巧夺冠)
- 水利水电工程单元工程施工质量检验表与验收表(SLT631.5-2025)
- JTS-131-2012水运工程测量规范
- DZ∕T0312-2018 非金属矿行业绿色矿山建设规范(正式版)
- 危大工程安全监理实施细则
- 等效声级计算表
- 电气施工方案罗湖二线插花地项目
- AS9120B程序文件一整套
- 门脉高压性消化道出血的介入治疗
- 项目监理机构人员配置标准(试行)
- VarianVS氦质谱检漏仪简介课件
评论
0/150
提交评论