Payday Loan Payday Loan

You can pass some info’s that you need to the next Intent by following the next steps:
You can send a String, a int value, a long, char, or any other value just like this:
FirstIntent.java

package com.intents;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
 
 
public class FirstIntent extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.firstintent);
/*when we click this button z...we lunch a new Activity called SecondIntent but we send also 2 values...
a string, and a int declared and initialized below...This values can be whatever you need to transmit to the other Intent..*/
String value1="Example of String";
int value2=3;
 Button z=(Button)findViewById(R.id.Button01);
 
 z.setOnClickListener(new OnClickListener(){
 
			@Override
			public void onClick(View v) {
				 Intent intent = new Intent( getBaseContext(),SecondIntent.class);
 
                                  intent.putExtra("keyword1",value1);
                                  intent.putExtra("keyword2",value2);		
		    startActivity( intent);
 
 
			}}); 
}
}

Code for the SecondIntent.java where we will put these values in same type of variables and we will use them as we want:

package com.intents;
 
import android.app.Activity;
import android.os.Bundle;
 
 
 
public class SecondIntent extends Activity{
		 @Override
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.secondintent);
	          Bundle extras=getIntent().getExtras();
	     String value1=extras.getString("keyword1"));
int value2=extras.getInt("keyword2");}
//we have just loaded our values so we use them and display them in a Toast
 
  Toast.makeText(getBaseContext(), value1, Toast.LENGTH_LONG).show();
  Toast.makeText(getBaseContext(), value2, Toast.LENGTH_LONG).show();
}
}
||||| 5 I Like It! |||||

Search

Popular

Sponsors