`

android 跳转并传递参数

 
阅读更多

 

package com.sun.hello;

import android.app.Activity;

import android.content.Intent;

import android.location.GpsStatus.Listener;

import android.net.Uri;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.Toast;

 

public class HelloActivity extends Activity {

private Button button = null;

 

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

button = (Button) findViewById(R.id.but1);

button.setOnClickListener(listener);

}

private OnClickListener listener = new OnClickListener() {

public void onClick(View v) {

// TODO Auto-generated method stub

Intent intent = new Intent();

intent.setClass(HelloActivity.this, SecondActivity.class);//

intent.putExtra("str","Intent demo");

startActivity(intent);

 

}

};

}

 

SecondActivity。java

package com.sun.hello;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.widget.Button;

import android.widget.TextView;

 

public class SecondActivity extends Activity {

private Button button;

private TextView secondTxt;

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.secondmain);

Intent intent=getIntent();

Bundle bundle=intent.getExtras();

String str=bundle.getString("str");

secondTxt=(TextView)findViewById(R.id.secondTxt);

secondTxt.setText(str);

}

}





main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />
<Button 
   android:id="@+id/but1"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="Call"
   />
    

</LinearLayout>


secondmain.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/secondTxt"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="second" />
<Button 
   android:id="@+id/secondbut1"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="SecondText"
   />
    

</LinearLayout>




AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.sun.hello"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".HelloActivity"
            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=".SecondActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.SEND_SMS"/>
</manifest>
分享到:
评论

相关推荐

    Android-Android界面跳转传递参数封装

    `Android-Android界面跳转传递参数封装`这个主题主要关注如何通过编程的方式优化这一过程,提高代码的可读性和可维护性。通常,开发者会使用Intent来实现Activity之间的通信,包括启动新的Activity和传递数据。下面...

    Androidstudio实现页面跳转和传递参数

    本篇文章将详细介绍如何在Android Studio中进行页面跳转并传递参数,以及如何利用Bundle对象来存储和恢复数据。 首先,页面跳转在Android中主要通过Intent对象来实现。Intent是一种用来表达应用程序之间意图的类,...

    Android 开发Activity基础 启动和跳转并传递参数

    了解Activity的基础,特别是如何启动、跳转以及传递参数,是每个Android开发者必须掌握的关键技能。 一、Activity的基础概念 Activity是Android系统中负责与用户交互的组件,它负责展示UI和处理用户事件。每个...

    Android原生java语句 和html js互相调用 传递参数

    本教程将详细介绍如何在Android中通过Java语句与HTML中的JavaScript进行互调,并传递参数。 首先,我们需要在Android项目中引入`WebView`组件。在XML布局文件中添加一个`WebView`: ```xml android:id="@+id/...

    Android Activity之间的跳转以及传递参数源代码下载

    要传递参数,我们可以利用Intent的putExtra()和getExtra()方法。比如,我们想传递一个字符串: ```java // 在源Activity中设置参数 intent.putExtra("key", "value"); // 在目标Activity中获取参数 String value =...

    android Web跳转到app指定页面并传递参数实例

    "Android Web 跳转到 App 指定页面并传递参数实例" Android Web 跳转到 App 指定页面并传递参数实例是指在 Android 系统中,通过 Web 端跳转到 App 中的指定页面,并传递参数的过程。这个过程需要在 Android 端和 ...

    Android 单击实现页面跳转

    Intent构造函数的第一个参数是当前Activity(`MainActivity.this`),第二个参数是要跳转的目标Activity(`NextActivity.class`)。`startActivity`方法用于启动目标Activity,从而完成页面跳转。 除了直接通过...

    Android通过Intent跳转地图应用(百度地图、高德地图)

    本篇文章将深入讲解如何使用Intent在Android应用中跳转到这些地图应用,并在用户未安装相应地图应用时提供备选方案,如打开网页版地图。 首先,我们需要了解Intent的基本结构。Intent通常由两部分组成:Action和...

    Android中Activity之间跳转和参数传递的实例

    以下将详细介绍如何在Android中实现Activity的跳转以及如何在跳转过程中传递参数。 首先,要创建一个新的Activity,你需要在项目的src目录下新建一个Java类,并让它继承自`Activity`基类。例如,你可以创建一个名为...

    android应用跳转界面

    在Android应用开发中,页面跳转是用户交互的基础,它涉及到Activity的概念以及Intent的使用。在Eclipse这个经典的Android开发环境中,我们通常会通过编写Java代码来实现页面间的跳转。接下来,我们将深入探讨Android...

    Android Activity跳转和listview的使用

    在这个主题中,我们将深入探讨如何通过Intent和Bundle实现Activity间的参数传递和跳转,以及如何在ListView中设置Item的点击事件处理。 首先,Intent是Android系统中用于启动其他组件(如Activity、Service等)的...

    Fragment跳转时传递参数及结果回传的方法(推荐)

    源Fragment中设置监听器并传递参数: ```java Fragment2 fragment2 = new Fragment2(); fragment2.setDataPassListener(new Fragment2.OnDataPassListener() { @Override public void onDataPass(String data...

    Activity跳转时传递Bitmap对象

    本篇文章将深入探讨如何在Activity跳转时传递Bitmap对象,并以一个Demo为例进行讲解。 首先,理解Bitmap的基本概念。Bitmap对象存储了图像的像素数据,可以是位图或压缩格式。它们占用大量的内存,因此在处理时需要...

    Android Activity中使用Intent实现页面跳转与参数传递的方法

    首先,让我们来看一下在`FirstActivity`中如何创建Intent并传递参数。在`onClick`方法中,我们首先实例化一个新的Intent对象: ```java Intent intent = new Intent(); ``` 然后,我们可以使用`putExtra()`方法来...

    android跳转系统和自己的应用

    在Android开发中,应用间的跳转以及与系统功能的交互是一项基本且重要的技能。通过合理的使用Intent,开发者能够实现各种跨应用或系统级别的操作,极大地增强了应用的功能性和用户体验。以下是对给定文件中的示例...

    Android之Activity的生命周期和Activity间的跳转和数据传递)

    ### Android之Activity的生命周期与Activity间的跳转及数据传递 #### Activity的概念与作用 在Android应用开发中,`Activity`是四大组件之一,主要负责管理应用程序的用户界面(UI)。一个Activity代表一个屏幕上的...

    基于Android的Activity跳转

    本篇文章将详细探讨如何在Android Studio环境下利用Intent进行Activity的跳转,包括显式跳转和隐式跳转,并涵盖带有参数传递及返回值的场景。 首先,我们来了解Intent的基本概念。Intent在Android中扮演着消息传递...

    页面跳转和数据传递

    在Web开发中,页面跳转和数据传递是两个至关重要的概念,它们构成了用户与应用程序交互的基础。页面跳转允许用户在不同的网页之间导航,而数据传递则是确保在这些跳转过程中信息得以保留或传递的关键机制。 ### ...

    android两个app实现跳转

    但是,跳转前的App需要有权限访问目标App的Activity,这通常通过在AndroidManifest.xml中声明`&lt;activity&gt;`标签,并添加`&lt;category android:name="android.intent.category.BROWSABLE" /&gt;`和`&lt;data&gt;`标签来实现。...

Global site tag (gtag.js) - Google Analytics