不同activity之間資料的傳遞

2021-08-20 03:07:24 字數 1592 閱讀 9313

不同activity之間的資料的傳遞有多種方式,這裡主要記錄兩種方式。第一種是通過bundle來傳遞資料,第二種方法就是直接通過intent來傳遞資料。

通過bundle來傳遞資料,首先在主activity中將需要傳遞的資料封裝儲存到bundle中,該部分**如下:

bundle bundle=new bundle();                        

intent intent=new intent();

bundle.putcharsequense("user",user); //將user資料通過bundle進行封裝到乙個名字為user的包裡

bundle.putcharsequense("password",password);

intent.putextras(bundle);

intent intent=new intent();

intent.putextra("com.mingrisoft.user",user);

intent.putextra("com.mingrisoft.password",password);

//將bundle物件新增到intent物件中

之後需要在目標activity中將該資料取出,方法如下:

intent intent=new intent();

bundle bundle=intent.getextras(); //此處取出的bundle為乙個陣列

string user=bundle.getstring("user"); //通過包名取出對應的資料

string password=bundle.getstring("passwoed");

通過intent直接傳遞資料,首先在主activity中將需要傳遞的資料封裝儲存到intent中,該部分**如下:

intent intent = new intent();

// intent.setclass(registeredactivity.this, landingactivity.class);

intent.putextra("username", un.gettext().tostring());

intent.putextra("password", pw.gettext().tostring());

// intent.setclass(registeredactivity.this, landingactivity.class);

// startactivity(intent);

之後同樣需要在目標activity中將該資料取出,方法如下:

intent intent=getintent();   //獲得intent 

string username=intent.getstringextra("username"); //將註冊的賬號密碼自動填入登陸介面

string password=intent.getstringextra("password");

Android 不同Activity之間的資料傳遞

在activity中呼叫另乙個activity時,需要呼叫startactivity intent i 若需要在呼叫另外乙個activity的同時傳遞資料,那麼就需要利用android.os.bundle物件封裝資料的能力,將欲傳遞的資料或引數,通過bundle來傳遞不同intent之間的資料。bu...

hadoop 不同集群之間資料拷貝

hadoop不同集群之間資料拷貝,拷貝時兩個集群要用active namenode去拷貝,datanode是不具備拷貝功能的,所以當我們把資料拿到hdfs路徑上時,要去判斷當前集群哪個主節點是active的,所以大致步驟為 資料落到hdfs上 beeline u jdbc hive2 e inser...

Oracle Tablespace之間資料遷移

size large 分割槽表常用的資料字典 分割槽表資訊 dba part tables 顯示分割槽 dba tab partitions 顯示子分割槽 dba tab subpartitions 顯示分割槽列 dba part key columns 顯示子分割槽列 dba subpart de...