In Android: How do I get variables/data from one screen to another?

前端 未结 4 1395
一整个雨季
一整个雨季 2020-12-03 16:05

In android: I\'m trying to take data from one activity/screen to another.

Let\'s say I\'m adding two numbers. I layout my first screen (xml) with 2 EditText views, a

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-03 16:46

    Take a look at the Some Intent examples section (from Common Tasks and How to Do Them in Android):

    basically, you use myIntent.putExtra (...) to send data (can be String, Int, Boolean etc) to the other receiving end (the other activity)...

    then, result will be passed back into the calling Activity's onActivityResult() method:

    protected void onActivityResult(int requestCode, int resultCode, Intent data){
        // See which child activity is calling us back.
        switch (resultCode) {
            case CHOOSE_FIGHTER:
                // This is the standard resultCode that is sent back if the
                // activity crashed or didn't doesn't supply an explicit result.
                if (resultCode == RESULT_CANCELED){
                    myMessageboxFunction("Fight cancelled");
                } 
                else {
                    myFightFunction(data);
                }
            default:
                break;
        }
    

    H.

提交回复
热议问题