0

I just want to show an simple Employee record on next layoutPage/Activity !!

this is my EmpLogin Java File

public class EmpLogin extends Activity {

private Button show;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.test);
    // TODO Auto-generated method stub

    show=(Button)findViewById(R.id.show);

    show.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub

            EditText no=(EditText)findViewById(R.id.getno);

            EditText name=(EditText)findViewById(R.id.getname);

            EditText sal=(EditText)findViewById(R.id.getsalary);

        Intent emp = new Intent(getApplicationContext(),EmpShow.class);


            emp.putExtra("EmpNO",(no.getText().toString()));

            emp.putExtra("EmpName",(name.getText().toString()));

            emp.putExtra("Sal",(sal.getText().toString()));

            startActivity(emp);
            }
    });

    }

}

How to use Retrieve data from the Intent ??? By using getExtra() method ??? or there is simple way ?? this my EmpShow.class file !!

public class EmpShow extends Activity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

     setContentView(R.layout.empshow);
    // TODO Auto-generated method stub

     Intent show = getIntent();     
     }
}
Xy1ys
  • 25
  • 3
  • 5

2 Answers2

0

As you passed data insideintent, So try to fetch the intent which has started your activity using the getIntent() method:

Intent intent = getIntent();

If your extra data is represented as strings, then you can use

intent.getStringExtra(String name) method.


As per your OP's class and intent. Here is the snipped which can fetch the values from your intent against respective variable,

public class EmpShow extends Activity 
{
@Override
public void onCreate(Bundle savedInstanceState) 
    {
super.onCreate(savedInstanceState);
   setContentView(R.layout.empshow);
   Intent intent = getIntent();     
   String empNo = intent.getStringExtra("EmpNO");
   String empNname = intent.getStringExtra("EmpName");
   String empSal = intent.getStringExtra("sal");
    }
 }
Vikalp Patel
  • 10,669
  • 6
  • 61
  • 96
0
 First Activity:
 Intent i=new Intent(FirstActivity.this,SecondActivity.class);
 i.putExtra("VAL",value1);
 startActivity(i);
 Second Activity:
 Intent getI=getIntent();
 String a =getI.getStringExtra("VAL");