每隻App是透過許多畫面所組成的,當然可能主畫面之外,都會有許多其他的頁面

再Android 設計中畫面會有配合的Activity 當然在這之前,最好事先了解一下,Android 關於生命週期的規劃

關於Activity 的生命週期可以參考這篇

http://docs.xamarin.com/guides/android/application_fundamentals/activity_lifecycle

我們看看今天的範例..


兩個按鈕,第一個按鈕(btn1) 按下後,會呼叫起Child1Activity

這邊不難,直接看程式

var btn1 = FindViewById<Button>(Resource.Id.btn1);
btn1.Click += delegate
{
          StartActivity(typeof(Child1Activity));
};

很簡單,如果不需要帶資料給另外一個Activity  直接透過StartActivity 就可以呼叫起來

再來第二個按鈕(btn2) 我們要把Child2Activity給叫起來之外我們必須要把一些資料帶過去

這時候要透過intent (意圖),為什麼會這樣設計呢?!這關係到因為很多時候,在Android 中會有許多Activity會被不只是自己開發的App給叫起

有可能會是系統發給你的,所以都得透過Intent去做處理,其中案例我帶一個key 為 username 值為 donma的資料過去

var btn2 = FindViewById<Button>(Resource.Id.btn2);
btn2.Click += delegate
{
 
    var intentAct2 = new Intent(this, typeof(Child2Activity));
    //將intent 放入username的值為donma 帶過去
    intentAct2.PutExtra("username", "donma");
    StartActivity(intentAct2);
 
};

在Activity 這邊,原本android 是要透過getIntent 取得,但是在Xamarin 直接就可以在 this.Intent 中拿到

Child2Activity.cs:

using Android.App;
using Android.OS;
using Android.Widget;
 
namespace NewActivity
{
    [Activity(Label = "My Activity")]
    public class Child2Activity : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Child2);
            var username = Intent.GetStringExtra("username") ?? "無資料";
            var tvChild2View = FindViewById<TextView>(Resource.Id.tvChild2View);
 
            tvChild2View.Text = "傳來的資料:" + username; 
        }
    }
}

結果:


成功拉是不是沒很難 :)

[Xamarin] 開啟另外一個Activity 並且帶資料 (转帖)的更多相关文章

  1. [Xamarin] 透過WebClient跟網路取得資料 (转帖)

    之前寫過一篇文章,關於在Android上面取得資料 透過GET方式傳資料給Server(含解決中文編碼問題) 我們來回顧一下 Android 端的Code: 有沒有超多,如果是在Xaramin下面,真 ...

  2. Delphi APP 開發入門(八)SQLite資料庫

    Delphi APP 開發入門(八)SQLite資料庫 分享: Share on facebookShare on twitterShare on google_plusone_share   閲讀次 ...

  3. 開啟活動監視器 (SQL Server Management Studio)

    本主題描述如何開啟 [活動監視器] 來取得有關 SQL Server 處理序以及這些處理序如何影響目前 SQL Server 執行個體的資訊. 此外,本主題也描述如何設定 [活動監視器] 的重新整理間 ...

  4. [ Eclipse ] [ Problem ] Eclipse 無法開啟問題

    因為 Eclipse 在設定環境的過程掛掉太多次,擷取一些網路上優秀的文章當作備份 http://www.ewdna.com/2013/12/Eclipse-Loading-Workbench.htm ...

  5. office outlook 無法開啟 outlook 視窗

    例如[無法啟動Microsoft Office Outlook.無法開啟Outlook 視窗.] 1.啟動 Outlook 安全模式outlook.exe /safe2.清除並重新產生目前設定檔的功能 ...

  6. 開啟windows 7 ,10 的熱點功能(無線熱點)

    開啟windows 7 ,10 的熱點功能: 1.首先要確定你的電腦無線芯片有無熱點功能  # netsh wlan show drivers    Hosted network supported ...

  7. [Xamarin] 關於Internal Storage ,存取App內部使用資料 (转帖)

    最近在開發App,會使用到必須要處理一些App所使用的資料,上網路查一下Android 得作法,包含我自己也實作了一下,可能是因為對Java || Android 不是很孰悉,常常錯在 java.la ...

  8. [Xamarin.Android] 儲存資料於Windows Azure (转帖)

    在準備討論Xamarin.Android 如何整合GCM與Windows Azure來實作Push Notification之前, 先來了解如何將Xamarin.Android 與Windows Az ...

  9. .net批量上傳Csv檔資料應用程序開發總結

    應用環境:visual studio 2010開發工具,Database為Sql2008以上版本 最近在生產環境中需要開發一款應用程式,上傳電子檔(.csv)資料至Database 最初方案: 以tx ...

随机推荐

  1. [GO]conext的使用

    package main import ( "context" "time" "net/http" "fmt" &quo ...

  2. xib下这种方式创建cell

      这种方法在iOS5.0之前是不能够创建成功的.   MEConvertListTableViewCell *cell = [tableView dequeueReusableCellWithIde ...

  3. VS2015安装失败

    [16D4:18C8][2017-06-24T13:44:01]e000: Error 0x80091007: Hash mismatch for path: D:\Visual Studio 201 ...

  4. 解决阿里云OSS跨域问题

    解决阿里云OSS跨域问题 现象 本人项目中对阿里云图片请求进行了两次,第一次通过img标签进行,第二次通过异步加载获取.第一次请求到图片,浏览器会进行缓存,随后再进行异步请求,保存跨域失效. 错误信息 ...

  5. Oracle EBS Export File Format

    Profile Option Name Site Application Responsibility Server Server Org User Remark Export MIME type t ...

  6. Mysql错误: ERROR 1205: Lock wait timeout exceeded try restarting transaction解决办法

    select * from information_schema.INNODB_TRX;show full processlist;//找出目前连接的列表kill ID//根据ID kill掉

  7. SQL 从数据库中随机取n条数据

    用NEWID()方法. * ,NEWID() AS random from [toblename] order by random 其中的1可以换成其他任意整数,表示取的数据条数

  8. bat windows10系统垃圾清理---

    @echo off color 0a title windows10系统垃圾清理--- echo ★☆ ★☆ ★☆ ★☆ ★☆★☆★☆ ★☆ ★☆ ★☆ ★☆★ echo ★☆ ★☆ ★☆ ★☆ ★☆ ...

  9. 没有xaml的WPF

    出于强迫症,我查了一下文档弄明白了WPF脱离xaml应该怎么搞.当然其实本质是为了MaxScript里使用做准备. using System; using System.Windows; using ...

  10. python 缺失值处理(Imputation)

    一.缺失值的处理方法 由于各种各样的原因,真实世界中的许多数据集都包含缺失数据,这些数据经常被编码成空格.nans或者是其他的占位符.但是这样的数据集并不能被scikit - learn算法兼容,因为 ...