Advertisement
Guest User

Untitled

a guest
Feb 9th, 2015
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.58 KB | None | 0 0
  1. package course.labs.intentslab;
  2.  
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.net.Uri;
  6. import android.os.Bundle;
  7. import android.util.Log;
  8. import android.view.View;
  9. import android.view.View.OnClickListener;
  10. import android.widget.Button;
  11. import android.widget.TextView;
  12.  
  13. public class ActivityLoaderActivity extends Activity {
  14.    
  15.     static private final int GET_TEXT_REQUEST_CODE = 1;
  16.     static private final String URL = "http://www.google.com";
  17.     static private final String TAG = "Lab-Intents";
  18.    
  19.     // For use with app chooser
  20.     static private final String CHOOSER_TEXT = "Load " + URL + " with:";
  21.    
  22.     // TextView that displays user-entered text from ExplicitlyLoadedActivity runs
  23.     private TextView mUserTextView;
  24.    
  25.     @Override
  26.     protected void onCreate(Bundle savedInstanceState) {
  27.         super.onCreate(savedInstanceState);
  28.         setContentView(R.layout.activity_loader_activity);
  29.        
  30.         // Get reference to the textView
  31.         mUserTextView = (TextView) findViewById(R.id.textView1);
  32.        
  33.         // Declare and setup Explicit Activation button
  34.         Button explicitActivationButton = (Button) findViewById(R.id.explicit_activation_button);
  35.         explicitActivationButton.setOnClickListener(new OnClickListener() {
  36.            
  37.             // Call startExplicitActivation() when pressed
  38.             @Override
  39.             public void onClick(View v) {
  40.                
  41.                 startExplicitActivation();
  42.                
  43.             }
  44.         });
  45.        
  46.         // Declare and setup Implicit Activation button
  47.         Button implicitActivationButton = (Button) findViewById(R.id.implicit_activation_button);
  48.         implicitActivationButton.setOnClickListener(new OnClickListener() {
  49.            
  50.             // Call startImplicitActivation() when pressed
  51.             @Override
  52.             public void onClick(View v) {
  53.                
  54.                 startImplicitActivation();
  55.                
  56.             }
  57.         });
  58.        
  59.     }
  60.    
  61.    
  62.     // Start the ExplicitlyLoadedActivity
  63.    
  64.     private void startExplicitActivation() {
  65.        
  66.         Log.i(TAG,"Entered startExplicitActivation()");
  67.        
  68.         // TODO - Create a new intent to launch the ExplicitlyLoadedActivity class
  69.         Intent explicitIntent = null;
  70.         explicitIntent = new Intent(ActivityLoaderActivity.this, ExplicitlyLoadedActivity.class);
  71.  
  72.  
  73.         // TODO - Start an Activity using that intent and the request code defined above
  74.         startActivityForResult(explicitIntent, GET_TEXT_REQUEST_CODE);
  75.        
  76.        
  77.     }
  78.    
  79.     // Start a Browser Activity to view a web page or its URL
  80.    
  81.     private void startImplicitActivation() {
  82.        
  83.         Log.i(TAG, "Entered startImplicitActivation()");
  84.        
  85.         // TODO - Create a base intent for viewing a URL
  86.         // (HINT:  second parameter uses Uri.parse())
  87.        
  88.         Intent baseIntent = null;
  89.        
  90.         // TODO - Create a chooser intent, for choosing which Activity
  91.         // will carry out the baseIntent
  92.         // (HINT: Use the Intent class' createChooser() method)
  93.         Intent chooserIntent = null;
  94.        
  95.        
  96.         Log.i(TAG,"Chooser Intent Action:" + chooserIntent.getAction());
  97.        
  98.        
  99.         // TODO - Start the chooser Activity, using the chooser intent
  100.  
  101.        
  102.     }
  103.    
  104.     @Override
  105.     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  106.        
  107.         Log.i(TAG, "Entered onActivityResult()");
  108.        
  109.         // TODO - Process the result only if this method received both a
  110.         // RESULT_OK result code and a recognized request code
  111.         // If so, update the Textview showing the user-entered text.
  112.         if (resultCode == RESULT_OK && requestCode == 1) {
  113.         mUserTextView.setText("Text" + data.getStringExtra("text"));
  114.  
  115.         }
  116.    
  117.    
  118.    
  119.    
  120.    
  121.     }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement