欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android編程中Intent實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)功能詳解

 更新時(shí)間:2017年07月28日 11:12:25   作者:LoveJulin  
這篇文章主要介紹了Android編程中Intent實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)功能,結(jié)合實(shí)例形式分析了Android Intent實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)功能的具體步驟與相關(guān)注意事項(xiàng),需要的朋友可以參考下

本文實(shí)例講述了Android編程中Intent實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)功能。分享給大家供大家參考,具體如下:

安卓四大組件:Activity、Service、Broadcast Receiver、Content Provider

Intent實(shí)現(xiàn)頁(yè)面之間跳轉(zhuǎn)

1、無(wú)返回值

startActivity(intent)

2、有返回值

startActivityForResult(intent,requestCode);
onActivityResult(int requestCode,int resultCode,Intent data)
setResult(resultCode,data);

FActivity.java

package com.example.hello;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class FActivity extends Activity{
  private Button bt1;
  private Context mContext;
  private Button bt2;
  private TextView tv;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.factivity);
    /*
     * 通過(guò)點(diǎn)擊bt1實(shí)現(xiàn)頁(yè)面之間的跳轉(zhuǎn)
     * 1.startActivity來(lái)實(shí)現(xiàn)跳轉(zhuǎn)
     * 1>初始換Intent
     */
    mContext = this;
    bt1 = (Button) findViewById(R.id.button1_first);
    bt2 = (Button) findViewById(R.id.button2_second);
    tv = (TextView) findViewById(R.id.textView1);
    //注冊(cè)點(diǎn)擊事件
    bt1.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        /**
         * 第一個(gè)參數(shù),上下文對(duì)象this
         * 第二個(gè)參數(shù),目標(biāo)文件
         */
        Intent intent = new Intent(mContext, SActivity.class);
        startActivity(intent);
      }
    });
    /*
     * 通過(guò)startActivityForResult
     * 第二個(gè)參數(shù)是請(qǐng)求的一個(gè)標(biāo)識(shí)
     */
    bt2.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        Intent intent = new Intent(mContext, SActivity.class);
        startActivityForResult(intent, 1);
      }
    });
  }
  /*
   * 通過(guò)startActivityForResult 跳轉(zhuǎn),接受返回?cái)?shù)據(jù)的方法
   * requestCode:請(qǐng)求標(biāo)識(shí)
   * resultCode:第二個(gè)頁(yè)面返回的標(biāo)識(shí)
   * data 第二個(gè)頁(yè)面回傳的數(shù)據(jù)
   */
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 1 && resultCode == 2) {
      String content = data.getStringExtra("data");
      tv.setText(content);
    }
  }
}

factivity.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" >
  <Button
    android:id="@+id/button1_first"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="第一種啟動(dòng)方式" />
  <Button
    android:id="@+id/button2_second"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="第二種啟動(dòng)方式" />
  <TextView
    android:id="@+id/textView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="把第二個(gè)頁(yè)面回傳的數(shù)據(jù)顯示出來(lái)" />
</LinearLayout>

SActivity.java

package com.example.hello;
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 SActivity extends Activity{
  private Button bt;
  private String content = "你好";
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sactivity);
    /*
     * 第二個(gè)頁(yè)面什么時(shí)候回傳數(shù)據(jù)給第一個(gè)頁(yè)面
     * 回傳到第一個(gè)頁(yè)面的,實(shí)際上是一個(gè)Intent對(duì)象
     */
    bt = (Button) findViewById(R.id.button1);
    bt.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        Intent data = new Intent();
        data.putExtra("data", content);
        setResult(2, data);
        //結(jié)束當(dāng)前頁(yè)面
        finish();
      }
    });
  }
}

sactivity.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" >
  <Button
    android:id="@+id/button1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Button" />
</LinearLayout>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.hello"
  android:versionCode="1"
  android:versionName="1.0" >
  <uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="21" />
  <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
      android:name=".MainActivity"
      android:label="@string/app_name" >
    </activity>
    <activity
      android:name=".FActivity"
      android:label="@string/app_name" >
      <!-- 首啟動(dòng)項(xiàng) -->
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    <activity
      android:name=".SActivity"
      android:label="@string/app_name" >
    </activity>
  </application>
</manifest>

用瀏覽器打開(kāi)網(wǎng)頁(yè)

Uri uri = Uri.parse("http://www.baidu.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《Android圖形與圖像處理技巧總結(jié)》、《Android開(kāi)發(fā)入門(mén)與進(jìn)階教程》、《Android調(diào)試技巧與常見(jiàn)問(wèn)題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • Android自定義軟鍵盤(pán)的步驟記錄

    Android自定義軟鍵盤(pán)的步驟記錄

    Android軟鍵盤(pán)這塊從我入職到現(xiàn)在,是一個(gè)一直糾纏我的問(wèn)題,這篇文章主要給大家介紹了關(guān)于Android自定義軟鍵盤(pán)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2021-08-08
  • Android Intent基礎(chǔ)用法及作用詳解

    Android Intent基礎(chǔ)用法及作用詳解

    Intent是一種重要的消息傳遞對(duì)象,用于在不同組件(如活動(dòng)(Activity)、服務(wù)(Service)、廣播接收器(BroadcastReceiver)等)之間進(jìn)行通信和交互,本文介紹Android Intent基礎(chǔ)用法及作用,感興趣的朋友一起看看吧
    2024-07-07
  • Android使用DrawerLayout仿QQ6.0雙側(cè)滑菜單

    Android使用DrawerLayout仿QQ6.0雙側(cè)滑菜單

    這篇文章主要為大家詳細(xì)介紹了Android使用DrawerLayout仿QQ6.0雙側(cè)滑菜單,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-08-08
  • Android實(shí)現(xiàn)通訊錄功能

    Android實(shí)現(xiàn)通訊錄功能

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)通訊錄功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-03-03
  • Android自定義ViewGroup實(shí)現(xiàn)淘寶商品詳情頁(yè)

    Android自定義ViewGroup實(shí)現(xiàn)淘寶商品詳情頁(yè)

    這篇文章主要為大家詳細(xì)介紹了Android自定義ViewGroup實(shí)現(xiàn)淘寶商品詳情頁(yè),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-10-10
  • Android操作存放在assets文件夾下SQLite數(shù)據(jù)庫(kù)的方法

    Android操作存放在assets文件夾下SQLite數(shù)據(jù)庫(kù)的方法

    這篇文章主要介紹了Android操作存放在assets文件夾下SQLite數(shù)據(jù)庫(kù)的方法,實(shí)例分析了Android操作SQLite數(shù)據(jù)庫(kù)的相關(guān)技巧,需要的朋友可以參考下
    2015-06-06
  • Android NDK開(kāi)發(fā)(C語(yǔ)言--動(dòng)態(tài)內(nèi)存分配)

    Android NDK開(kāi)發(fā)(C語(yǔ)言--動(dòng)態(tài)內(nèi)存分配)

    這篇文章主要介紹了Android NDK開(kāi)發(fā) C語(yǔ)言--動(dòng)態(tài)內(nèi)存分配
    2021-12-12
  • 最新評(píng)論