Intent有返回值得例子

2021-07-10 15:51:06 字數 616 閱讀 9360

intent有返回值得案例:

邏輯思維就是:把第乙個頁面的資料通過intent傳遞給第二個頁面,第二個頁面通過getintent()接收資料並處理過後,

在通過intent反傳給第乙個頁面,第乙個頁面通過從寫onactivityresult()方法接收並處理資料。

例項如下:

第乙個頁面傳遞資料:

intent intent=new intent(mainactivity.this,nextactivity.class);

intent.putextra("a", a+"+"+b+"=");

startactivityforresult(intent,1);

第二個頁面接收資料:

intent intent=getintent();

string s=intent.getstringextra("a");

第二個頁面返回值給第乙個頁面;

public void onclick(view v)

第乙個頁面接收第二個頁面的資料並判斷處理

protected void onactivityresult(int requestcode, int resultcode, intent data)

}

有返回值和無返回值函式

前面在定義函式時,有些函式使用了return語句,有些函式沒有使用return語句,使用return語句與不使用return語句有什麼區別呢?由前面的章節我們知道,若定義函式時沒有使用return語句,則預設返回乙個none。要返回乙個none,可以只寫乙個return,但要返回具體的數值,就需要在...

返回值還引數 有返回值有引數的資料運算

有乙個引數有返回值的函式 include include int f int x 函式y 2x 1int add int x 自加函式int main 實現的功能是計算f x 的值,f x 2x 1,以及乙個自加函式return的作用是把函式執行的結果返回給呼叫者,返回值是什麼取決於return後面...

建構函式有返回值

function f1 console.log new f1 返回例項,委託原型 console.log new f1 name f1 console.log f1 name uncaught typeerror cannot read property name of undefined cons...