每隻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. Hello_Depth_Perception 任务二:Project Tango采集深度感知数据

    Java API Depth Perception Tutorial深度感知教程 Configuration 配置信息 In order to use depth perception, your T ...

  2. ZOJ3704 I am Nexus Master! 2017-04-06 23:36 56人阅读 评论(0) 收藏

    I am Nexus Master! Time Limit: 2 Seconds      Memory Limit: 65536 KB NexusHD.org is a popular PT (Pr ...

  3. underscore概况

    看的是1.3.3,这个版本的中文源码解释比较多. 函数的中文注释:http://www.css88.com/doc/underscore1.5.2/#difference 源码的中文注释:http:/ ...

  4. After Upgrade To Release 12.1.3 Users Receive "Function Not Available To This Responsibility" Error While Selecting Sub Menus Under Diagnostics (Doc ID 1200743.1)

    APPLIES TO: Oracle Application Object Library - Version 12.1.3 to 12.1.3 [Release 12.1] Information ...

  5. Oracle EBS 快捷键

    打开菜单 Help > Keyboard Help... 功能                         快捷键 =================================== 1 ...

  6. Android-解析JSON数据(JSON对象/JSON数组)

    在上一篇博客中,Android-封装JSON数据(JSON对象/JSON数组),讲解到Android真实开发中更多的是去解析JSON数据(JSON对象/JSON数组) 封装JSON的数据是在服务器端进 ...

  7. ISO in CSS content

    Name   Numeric Description Hex ISO in CSS content Octal       no-break space %A0 p:before { content: ...

  8. asp.net 使用Oracle数据库

    asp.net下使用oracle会发生“未能加载文件或程序集‘Oracle.DataAccess’或它的某一个依赖项”的错误.这说明Oracle的驱动没有安装好,或者版本不对的错误. 1.检查Orac ...

  9. C# 多线程task

    1.异步和多线程的区别?没什么太大区别.异步是目的,使用多线程实现.想想AJAX异步加载,不就是不想让浏览器界面卡住嘛,所以在程序中对于某些单独的操作,比如写日志,我们不想等它完成后再执行其它操作(因 ...

  10. ASP.NET添加Mysql数据源

    在ASP.NET的数据源控件上添加mysql数据库连接,首先需要在windows系统下添加mysql的数据源才能在vs中添加数据源 1.在控制面板下打开系统与安全-->打开管理工具-->点 ...