Blog Details

img
Design

What is use of explicit intent for android

Spoke Right / 20 Nov, 2023

Android Explicit Intent

The component to be invoked from an activity, the Android Explicit intent is used. Thus, the explicit intent can be used to call another activity in android. The explicit intent is used to pass the information from one activity to another.

Example:

In the below example, we are demonstrating the usage of the android to call one activity from another and vice versa.

activity_main.xml:



 
    
 
    
    
 

ctivity class:(File: MainActivity.java)

package com.example.radioapp;
 
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
 
public class MainActivity extends Activity {
    // Defining the object for button
    Button button1;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        // Bind the components to their respective objects
        // by assigning their IDs
        // with the help of findViewById() method
        button1 = (Button)findViewById(R.id.Button01);
 
        button1.setOnClickListener(new OnClickListener() {
            public void onClick(View view)
            {
 
                // Creating explicit intent
                Intent i = new Intent(getApplicationContext(),
                        SecondActivity.class);
                startActivity(i);
            }
        });
    }
 
}

Activity_second.xml:(File: activity_second.xml)



 
    
 
    
    
 

SecondActivity class: (File: SecondActivity.java)

package com.example.radioapp;
 
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
 
public class SecondActivity extends Activity {
 
    // Defining the object for button
    Button button1;
    @Override
    public void onCreate(Bundle bundle)
    {
        super.onCreate(bundle);
        setContentView(R.layout.activity_second);
 
        // Bind the components to their respective objects
        // by assigning their IDs
        // with the help of findViewById() method
        button1 = (Button)findViewById(R.id.Button01);
 
        button1.setOnClickListener(new OnClickListener() {
            public void onClick(View view)
            {
 
                // Creating explicit intent
                Intent i = new Intent(getApplicationContext(),
                        MainActivity.class);
 
                startActivity(i);
            }
        });
    }}

AndroidManifest: (File:AndroidManifest.xml)



 
    
        
            
                
 
                
            
        
        
            
            
                
            
        
    
 

0 comments

Warning: PHP Startup: Unable to load dynamic library 'imagick.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20210902/imagick.so (/usr/local/lib/php/extensions/no-debug-non-zts-20210902/imagick.so: cannot open shared object file: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20210902/imagick.so.so (/usr/local/lib/php/extensions/no-debug-non-zts-20210902/imagick.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0