Explicit intent to send request one to another

By ukmodak | March 31st 2024 10:30:09 AM | viewed 923 times

create a main.xml layout and Add a button to show explicit intent in the location: layout(android studio)

<?xml version="1.0" encoding="utf-8"? >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >


        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="426dp" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:text="Welcome to main activity "
                android:textColor="#ffffff"
                android:textSize="15sp" />

             <Button
                android:id="@+id/btn_intent_explicit"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/btnLifeCycle"
                android:layout_below="@+id/btnLifeCycle"
                android:text="Intent(Explicit)"
                android:textSize="8sp" />
          

        </RelativeLayout>

    </LinearLayout>

</LinearLayout>

create a ProjectonOverallClassMainActivity activity to send request to another activity

package com.uk.modak;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class ProjectonOverallClassMainActivity extends Activity {
   
	
	public Button btn_intent_explicit;
		
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
               
         btn_intent_explicit = (Button) findViewById(R.id.btn_intent_explicit);             
        btn_intent_explicit.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {				
				Intent z = new Intent(ProjectonOverallClassMainActivity.this,ExplicitIntentHomeActivity.class);
				startActivity(z);
			}
		});                     
    }
    
    public void onStart(){
    	super.onStart();
    	 	
    }
      
    
}

create a explicitintenthome.xml layout to generate request(android studio)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:text="Welcome explicit home layout" />

        <Button
            android:id="@+id/btnTrue"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/textView1"
            android:layout_marginLeft="44dp"
            android:layout_marginTop="145dp"
            android:text="True" />

        <Button
            android:id="@+id/btnFalse"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/btnTrue"
            android:layout_alignBottom="@+id/btnTrue"
            android:layout_alignParentRight="true"
            android:layout_marginRight="49dp"
            android:text="False" />


        <EditText
            android:id="@+id/editTextShowTrueFalse"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/textView1"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="33dp"
            android:ems="10"
            android:inputType="textPersonName" >

            
        </EditText>



        <Button
            android:id="@+id/btnGoInnerPage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/btnTrue"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="74dp"
            android:text="Show result on inner page" />

    </RelativeLayout>

</LinearLayout>

create a ExplicitIntentHomeActivity to generate request(android studio)

package com.uk.modak;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class ExplicitIntentHomeActivity extends Activity {
	
	private EditText editTextShowTrueFalse;
	private Button btnTrue;
	private Button btnFalse;
	public Button btnGoInnerPage;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.explicitintenthome);
        
        editTextShowTrueFalse = (EditText) findViewById(R.id.editTextShowTrueFalse);
        btnTrue = (Button) findViewById(R.id.btnTrue);
        btnFalse = (Button) findViewById(R.id.btnFalse);
        btnGoInnerPage = (Button) findViewById(R.id.btnGoInnerPage);
        
      
       btnTrue.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				editTextShowTrueFalse.setText("True");

				//Toast.makeText(GeoQuizActivity.this,R.string.trueToast,Toast.LENGTH_LONG).show();
				
			}
		});
        
       btnFalse.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				editTextShowTrueFalse.setText("False");

				//Toast.makeText(GeoQuizActivity.this,R.string.false_Toast,Toast.LENGTH_LONG).show();
				
			}
		});
        
          btnGoInnerPage.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				
				Intent m = new Intent(ExplicitIntentHomeActivity.this,ExplicitIntentInnerActivity.class);				
				m.putExtra(ExplicitIntentInnerActivity.GET_RESULT, editTextShowTrueFalse.getText().toString());				
				startActivityForResult(m,0);
				
			}
		});
            
	}
	

}

create a explicitintentinner.xml layout to show result (android studio)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:text="Welcome to explicit inner layout" />

        <Button
            android:id="@+id/btnPress"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/textView1"
            android:layout_centerVertical="true"
            android:layout_marginLeft="42dp"
            android:text="Press" />       
			
    </RelativeLayout>

</LinearLayout>

create a ExplicitIntentInnerActivity to show result(android studio)

package com.uk.modak;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class ExplicitIntentInnerActivity extends Activity {
	
	public static final String GET_RESULT="";
	

	private Button btnPress;
	private String answer ="";
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.explicitintentinner);
        
     
        btnPress = (Button) findViewById(R.id.btnPress);
       
        System.out.println(GET_RESULT);
        System.out.println("next");

        answer = getIntent().getStringExtra(GET_RESULT);
        
        System.out.println(answer);
        
        btnPress.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				
				Toast.makeText(ExplicitIntentInnerActivity.this, answer,Toast.LENGTH_LONG).show();
				/*if(answer=="True")
				{
					edittextShowInner.setText("True");
				}
				else
				{
					edittextShowInner.setText("False");
				}*/
				
			}
		});
            
	}

}

to to menifeast and setup activity that we use

<application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".ProjectonOverallClassMainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
       
        <activity
            android:name=".ExplicitIntentInnerActivity"
            android:label="@string/app_name" >
        </activity>
        
        <receiver android:name=".ConnectionReceive">
            <intent-filter>
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
            </intent-filter>
        </receiver>
        
    </application>
bONEandALL
Visitor

Total : 26654

Today :3

Today Visit Country :

  • France
  • United States