1/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.example.android.supportv4.app;
18
19// Need the following import to get access to the app resources, since this
20// class is in a sub-package.
21
22import android.app.Activity;
23import android.content.Intent;
24import android.os.Bundle;
25import android.view.View;
26import android.view.View.OnClickListener;
27import android.widget.Button;
28
29import com.example.android.supportv4.R;
30
31
32/**
33 * Example of receiving a result from another activity.
34 */
35public class SendResult extends Activity
36{
37    /**
38     * Initialization of the Activity after it is first created.  Must at least
39     * call {@link android.app.Activity#setContentView setContentView()} to
40     * describe what is to be displayed in the screen.
41     */
42    @Override
43	protected void onCreate(Bundle savedInstanceState)
44    {
45        // Be sure to call the super class.
46        super.onCreate(savedInstanceState);
47
48        // See assets/res/any/layout/hello_world.xml for this
49        // view layout definition, which is being set here as
50        // the content of our screen.
51        setContentView(R.layout.send_result);
52
53        // Watch for button clicks.
54        Button button = (Button)findViewById(R.id.corky);
55        button.setOnClickListener(mCorkyListener);
56        button = (Button)findViewById(R.id.violet);
57        button.setOnClickListener(mVioletListener);
58    }
59
60    private OnClickListener mCorkyListener = new OnClickListener()
61    {
62        @Override
63        public void onClick(View v)
64        {
65            // To send a result, simply call setResult() before your
66            // activity is finished.
67            setResult(RESULT_OK, (new Intent()).setAction("Corky!"));
68            finish();
69        }
70    };
71
72    private OnClickListener mVioletListener = new OnClickListener()
73    {
74        @Override
75        public void onClick(View v)
76        {
77            // To send a result, simply call setResult() before your
78            // activity is finished.
79            setResult(RESULT_OK, (new Intent()).setAction("Violet!"));
80            finish();
81        }
82    };
83}
84
85