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.
21import com.example.android.supportv4.R;
22
23import android.app.Activity;
24import android.content.Intent;
25import android.os.Bundle;
26import android.view.View;
27import android.view.View.OnClickListener;
28import android.widget.Button;
29
30
31/**
32 * Example of receiving a result from another activity.
33 */
34public class SendResult extends Activity
35{
36    /**
37     * Initialization of the Activity after it is first created.  Must at least
38     * call {@link android.app.Activity#setContentView setContentView()} to
39     * describe what is to be displayed in the screen.
40     */
41    @Override
42	protected void onCreate(Bundle savedInstanceState)
43    {
44        // Be sure to call the super class.
45        super.onCreate(savedInstanceState);
46
47        // See assets/res/any/layout/hello_world.xml for this
48        // view layout definition, which is being set here as
49        // the content of our screen.
50        setContentView(R.layout.send_result);
51
52        // Watch for button clicks.
53        Button button = (Button)findViewById(R.id.corky);
54        button.setOnClickListener(mCorkyListener);
55        button = (Button)findViewById(R.id.violet);
56        button.setOnClickListener(mVioletListener);
57    }
58
59    private OnClickListener mCorkyListener = new OnClickListener()
60    {
61        @Override
62        public void onClick(View v)
63        {
64            // To send a result, simply call setResult() before your
65            // activity is finished.
66            setResult(RESULT_OK, (new Intent()).setAction("Corky!"));
67            finish();
68        }
69    };
70
71    private OnClickListener mVioletListener = new OnClickListener()
72    {
73        @Override
74        public void onClick(View v)
75        {
76            // To send a result, simply call setResult() before your
77            // activity is finished.
78            setResult(RESULT_OK, (new Intent()).setAction("Violet!"));
79            finish();
80        }
81    };
82}
83
84