Android explicit intent, implicit intent, intent filter (intent-filter), and inter-intention value transfer

Source: Internet
Author: User

Intent mainly includes implicit intent and explicit intent. Explicit intent is usually used to start data between activities in the current application, while implicit intent is commonly used in some specific actions in the startup system, such as making phone calls or sending text messages, or cross-app Activity startup (for example, clicking the link address on QQ to start a browser Activity ).

Explicit Intent: Call Intent. setComponent (), Intent. setClass (), Intent. the setClassName () method explicitly specifies the Intent of the component name as the explicit Intent, and the explicit Intent specifies the component to which the Intent should be passed.
Implicit Intent: Intent without explicitly specifying the component name is implicit Intent. The Android system will find the most suitable component to process the intent based on the action, category, and data (URI and data type) set in the implicit intent.

MainActivity. java

Package cn. android. intent; import java. util. date; import android. app. activity; import android. content. intent; import android. OS. bundle; import android. view. keyEvent; import android. view. view; import android. widget. textView; public class NewActivity extends Activity {@ Overrideprotected void onCreate (Bundle savedInstanceState) {// TODO Auto-generated method stubsuper. onCreate (savedInstanceState); setContentVi Ew (R. layout. other); Intent intent = getIntent (); // Log. I ("NewActivity", intent. getData (). getPath (); String title = intent. getStringExtra ("title"); double since = intent. getDoubleExtra ("since", 1995.5); TextView textView = (TextView) this. findViewById (R. id. textView); textView. setText ("language:" + title + ", Release Date:" + since + ". ");} Public void closeActivity (View v) {Intent intent = new Intent (); intent. putExtra ("result", new Date (). toString (); setResult (501, intent); this. finish () ;}@ Overridepublic boolean onKeyDown (int keyCode, KeyEvent event) {if (keyCode = KeyEvent. KEYCODE_BACK) {closeActivity (null) ;}return true ;}}

NewActivity. java
Package cn. android. intent; import java. util. date; import android. app. activity; import android. content. intent; import android. OS. bundle; import android. view. keyEvent; import android. view. view; import android. widget. textView; public class NewActivity extends Activity {@ Overrideprotected void onCreate (Bundle savedInstanceState) {// TODO Auto-generated method stubsuper. onCreate (savedInstanceState); setContentVi Ew (R. layout. other); Intent intent = getIntent (); // Log. I ("NewActivity", intent. getData (). getPath (); String title = intent. getStringExtra ("title"); double since = intent. getDoubleExtra ("since", 1995.5); TextView textView = (TextView) this. findViewById (R. id. textView); textView. setText ("language:" + title + ", Release Date:" + since + ". ");} Public void closeActivity (View v) {Intent intent = new Intent (); intent. putExtra ("result", new Date (). toString (); setResult (501, intent); this. finish () ;}@ Overridepublic boolean onKeyDown (int keyCode, KeyEvent event) {if (keyCode = KeyEvent. KEYCODE_BACK) {closeActivity (null) ;}return true ;}}

Main. xml
 
     
      
      
       
           
  
 

Other. xml
 
 
      
       
       
  
 

AndroidManifest. xml
 
     
                          
                                  
               
                              
  
                                   windowsphone" />                
                   
                   
                   
                   
               
              
 

Strings. xml
 
     
  
   
Hello World, MainActivity!
      
  
   
New Activity!
      
  
   
Android intent
  
  
   
Show
  
  
   
Open implicit intent
  
  
   
Close Window
  
 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.