Home | History | Annotate | Download | only in app
      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 
     17 package 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 import com.example.android.supportv4.R;
     22 
     23 import android.app.Activity;
     24 import android.content.Intent;
     25 import android.os.Bundle;
     26 import android.view.View;
     27 import android.view.View.OnClickListener;
     28 import android.widget.Button;
     29 
     30 
     31 /**
     32  * Example of receiving a result from another activity.
     33  */
     34 public 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         public void onClick(View v)
     62         {
     63             // To send a result, simply call setResult() before your
     64             // activity is finished.
     65             setResult(RESULT_OK, (new Intent()).setAction("Corky!"));
     66             finish();
     67         }
     68     };
     69 
     70     private OnClickListener mVioletListener = new OnClickListener()
     71     {
     72         public void onClick(View v)
     73         {
     74             // To send a result, simply call setResult() before your
     75             // activity is finished.
     76             setResult(RESULT_OK, (new Intent()).setAction("Violet!"));
     77             finish();
     78         }
     79     };
     80 }
     81 
     82