Android Activity跳转相关操作技巧分享

移动开发 Android
当我们在Android操作平台中想要实现一个屏幕的跳转的话,应当如何操作呢?在这里就为大家详细介绍一下Android Activity跳转的实现方法。

我们曾经在一篇文章中为大家详细介绍过有关Android Activity的相关内容。在这里,我们会进一步的对这一操作进行详细剖析。主要就是针对Android Activity跳转的实现。下面就让我们一起看看具体操作方法吧。

Android中提供一个叫Intent的类来实现屏幕之间的跳转,下面是一个简单的示例:

在应用中增加一个Activity(名字为.ForwardTarget),这需要修改AndroidManifest.xml文件,如下:

Android Activity跳转代码示例:

< ?xml version="1.0" encoding="utf-8"?>   
< manifest xmlns:android="< A href="http://schemas.android.com/
apk/res/android"
>http://schemas.android.com/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="android.intent.action.MAIN" />    < category android:name="android.intent.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=
"http://schemas.android.com/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="android.intent.action.MAIN" />  < category android:name="android.intent.category.LAUNCHER" />  < /intent-filter>  < /activity>  < activity android:name=".ForwardTarget">  < /activity>  < /application>  < uses-sdk android:minSdkVersion="3" />  < /manifest>  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.

然后在layout中的main加入一个id为leah1的按钮,另外再创建一个任意的layout(将要跳转到得layout),我取名为leah1。

接下来是两个类,一个是AndroidForward,另一个是将要跳转到得ForwardTarget,Android Activity跳转实现的代码分别如下:

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.leah1);   
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.leah1);   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.leah1);    }   
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.

Android Activity跳转的相关实现方法就为大家介绍到这里。

【编辑推荐】

  1. Android AlertDialog操作代码详解
  2. Android监听通话正确操作方法介绍
  3. Android震动代码解读
  4. Android移植实际应用要点解析
  5. Android启动Java程序应用方法详解
责任编辑:曹凯 来源: javaeye.com
相关推荐

2010-01-25 18:33:35

Android键盘操作

2010-01-25 17:21:34

Android Act

2009-12-10 17:27:39

PHP操作Cookie

2010-01-06 17:02:28

.Net Framew

2010-03-04 10:50:45

windows ser

2010-01-28 10:55:14

Android电源管理

2009-12-10 16:35:08

PHP操作文章列表

2011-04-12 17:16:52

Activity跳转开发实例Android学习笔记

2010-01-13 10:25:30

VB.NET文件夹操作

2010-01-13 15:33:40

VB.NET菜单项目

2010-01-28 16:55:26

Android对话框

2009-12-29 16:08:41

Silverlight

2010-02-22 17:58:06

WCF异步上传

2010-01-15 15:10:43

VB.NET Stri

2010-02-24 11:22:04

WCF方法重载

2009-12-30 13:37:24

Silverlight

2009-12-30 10:25:03

Silverlight

2010-03-03 16:57:28

Python字符

2010-01-04 14:49:30

Silverlight

2010-01-25 11:09:58

Android Htt
点赞
收藏

51CTO技术栈公众号