Android Activity中使用Intent實(shí)現(xiàn)頁面跳轉(zhuǎn)與參數(shù)傳遞的方法
本文實(shí)例講述了Android Activity中使用Intent實(shí)現(xiàn)頁面跳轉(zhuǎn)與參數(shù)傳遞的方法。分享給大家供大家參考,具體如下:
新建一個(gè)FirstAvtivity.java
package com.zhuguangwei;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class FirstActivity extends Activity {
private Button myButton;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myButton = (Button) findViewById(R.id.myButton);
myButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent();
//Intent傳遞參數(shù)
intent.putExtra("testIntent", "123");
intent.setClass(FirstActivity.this, SecondActivity.class);
FirstActivity.this.startActivity(intent);
}
});
}
}
新建第二個(gè)SecondActivity.java
package com.zhuguangwei;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class SecondActivity extends Activity{
private TextView myTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.other);
//使用Intent對(duì)象得到FirstActivity傳遞來的參數(shù)
Intent intent = getIntent();
String value = intent.getStringExtra("testIntent");
myTextView = (TextView) findViewById(R.id.myTextView);
myTextView.setText(value);
}
}
兩個(gè)Activity都要在AndroidMenifest.xml中注冊(cè)
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android視圖View技巧總結(jié)》、《Android操作SQLite數(shù)據(jù)庫技巧總結(jié)》、《Android操作json格式數(shù)據(jù)技巧總結(jié)》、《Android數(shù)據(jù)庫操作技巧總結(jié)》、《Android文件操作技巧匯總》、《Android編程開發(fā)之SD卡操作方法匯總》、《Android開發(fā)入門與進(jìn)階教程》、《Android資源操作技巧匯總》及《Android控件用法總結(jié)》
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
- Android Studio實(shí)現(xiàn)注冊(cè)頁面跳轉(zhuǎn)登錄頁面的創(chuàng)建
- Android實(shí)現(xiàn)頁面跳轉(zhuǎn)的全過程記錄
- Android使用Intent顯示實(shí)現(xiàn)頁面跳轉(zhuǎn)
- Android使用Intent隱式實(shí)現(xiàn)頁面跳轉(zhuǎn)
- Android Intent實(shí)現(xiàn)頁面跳轉(zhuǎn)的兩種方法
- Android Intent實(shí)現(xiàn)頁面跳轉(zhuǎn)的方法示例
- Android 實(shí)現(xiàn)頁面跳轉(zhuǎn)
- Android使用Circular Reveal動(dòng)畫讓頁面跳轉(zhuǎn)更炫酷
- Android編程中Intent實(shí)現(xiàn)頁面跳轉(zhuǎn)功能詳解
- Android實(shí)現(xiàn)頁面跳轉(zhuǎn)
相關(guān)文章
Android開發(fā)工程中集成mob短信驗(yàn)證碼功能的方法
這篇文章主要介紹了Android開發(fā)工程中集成mob短信驗(yàn)證碼功能的方法,感興趣的小伙伴們可以參考一下2016-05-05
android 震動(dòng)和提示音的實(shí)現(xiàn)代碼
這篇文章主要介紹了android 震動(dòng)和提示音的實(shí)現(xiàn)代碼,代碼簡單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-12-12
Android 簡單的彈出框(在屏幕中間,傳string[],根據(jù)內(nèi)容框框大小自適應(yīng))
這篇文章主要介紹了Android 簡單的彈出框(在屏幕中間,傳string[],根據(jù)內(nèi)容框框大小自適應(yīng)),需要的朋友可以參考下2017-04-04
Android實(shí)現(xiàn)記住用戶名和密碼功能
登陸界面創(chuàng)建一個(gè)復(fù)選按鈕,通過按鈕選取來進(jìn)行事件處理。若按鈕選中記住賬號(hào)和密碼的信息,本文教大家如何使用Android實(shí)現(xiàn)記住用戶名和密碼功能,感興趣的小伙伴們可以參考一下2016-05-05
Android使用Photoview實(shí)現(xiàn)圖片左右滑動(dòng)及縮放功能
這篇文章主要為大家詳細(xì)介紹了Android使用Photoview實(shí)現(xiàn)圖片左右滑動(dòng)及縮放功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-01-01
Android WebView支持input file啟用相機(jī)/選取照片功能
這篇文章主要介紹了Android-WebView支持input file啟用相機(jī)/選取照片功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-08-08

