tags:

views:

65

answers:

1

Alice has to answer three questions. After she answered the questions she gets a dialog that lists the question and answers and there's a button to save the answers to a database.

At the moment I think that the design should be three classes: Master, Question, Summary.

Master calls Question with an intent that includes the question text of question 1. After Alice inputs her answer the Question returns the answer to master via an intent.

Repeat two times.

Then Master does processing of the questions and calls Summary via an intent.

Is this kind of design recommendable in Android? Is it possible to have such an Master activity. If so, how can I allow a running master activity to listen to intents?

+2  A: 

What you are looking for is startActivityForResult

Returning a Result from a Screen

A window can return a result after it closes. This result will be passed back into the calling Activity's onActivityResult() method, which can supply an Intent containing arbitrary data, along with the request code passed to startActivityForResult(). Note that you must call the startActivityForResult() method that accepts a request code parameter to get this callback. The following code demonstrates opening a new screen and retrieving a result.

// Open the new screen.
public void onClick(View v){
    // Start the activity whose result we want to retrieve.  The
    // result will come back with request code GET_CODE.
    Intent intent = new Intent(this, com.example.app.ChooseYourBoxer.class);
    startActivityForResult(intent, CHOOSE_FIGHTER);
}

// Listen for results.
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;
    }
}



// Class SentResult
// Temporary screen to let the user choose something.
    private OnClickListener mLincolnListener = new OnClickListener(){
        public void onClick(View v) {
            Bundle stats = new Bundle();
            stats.putString("height","6\'4\""); 
            stats.putString("weight", "190 lbs");
            stats.putString("reach", "74\"");
            setResult(RESULT_OK, "Lincoln", stats);
            finish();
        }
    };

    private OnClickListener mWashingtonListener = new OnClickListener() {
        public void onClick(View v){
            Bundle stats = new Bundle();
            stats.putString("height","6\'2\""); 
            stats.putString("weight", "190 lbs");
            stats.putString("reach", "73\"");
            setResult(RESULT_OK, "Washington", Bundle);
            finish();
        }
    };
Pentium10