Android Activity中使用Intent實現(xiàn)頁面跳轉與參數(shù)傳遞的方法
本文實例講述了Android Activity中使用Intent實現(xiàn)頁面跳轉與參數(shù)傳遞的方法。分享給大家供大家參考,具體如下:
新建一個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);
}
});
}
}
新建第二個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對象得到FirstActivity傳遞來的參數(shù)
Intent intent = getIntent();
String value = intent.getStringExtra("testIntent");
myTextView = (TextView) findViewById(R.id.myTextView);
myTextView.setText(value);
}
}
兩個Activity都要在AndroidMenifest.xml中注冊
更多關于Android相關內容感興趣的讀者可查看本站專題:《Android編程之activity操作技巧總結》、《Android視圖View技巧總結》、《Android操作SQLite數(shù)據(jù)庫技巧總結》、《Android操作json格式數(shù)據(jù)技巧總結》、《Android數(shù)據(jù)庫操作技巧總結》、《Android文件操作技巧匯總》、《Android編程開發(fā)之SD卡操作方法匯總》、《Android開發(fā)入門與進階教程》、《Android資源操作技巧匯總》及《Android控件用法總結》
希望本文所述對大家Android程序設計有所幫助。
相關文章
Android開發(fā)工程中集成mob短信驗證碼功能的方法
這篇文章主要介紹了Android開發(fā)工程中集成mob短信驗證碼功能的方法,感興趣的小伙伴們可以參考一下2016-05-05
Android 簡單的彈出框(在屏幕中間,傳string[],根據(jù)內容框框大小自適應)
這篇文章主要介紹了Android 簡單的彈出框(在屏幕中間,傳string[],根據(jù)內容框框大小自適應),需要的朋友可以參考下2017-04-04
Android使用Photoview實現(xiàn)圖片左右滑動及縮放功能
這篇文章主要為大家詳細介紹了Android使用Photoview實現(xiàn)圖片左右滑動及縮放功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-01-01
Android WebView支持input file啟用相機/選取照片功能
這篇文章主要介紹了Android-WebView支持input file啟用相機/選取照片功能,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-08-08

