how to pass data using intent in android

Design your xml according to EditText,TextView,Button mention with id in Fisrt_Activity.java & second its too easy.

Fisrt_Activity.java


public class MainActivity extends Activity {

EditText user,password;
Button login;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    user=(EditText) findViewById(R.id.username_edit);
    password=(EditText) findViewById(R.id.edit_password);
    login=(Button) findViewById(R.id.btnSubmit);
    login.setOnClickListener(new OnClickListener() {

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

            Intent intent=new Intent(MainActivity.this,Second.class);
            String uservalue=user.getText().toString();
            String name_value=password.getText().toString();
            String password_value=password.getText().toString();
            intent.putExtra("username", uservalue);
            intent.putExtra("password", password_value);
            startActivity(intent);

        }
    });


}
}


Second_Activity.java

public class Second extends Activity{

EditText name,pass;
@Override

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.second_activity);

    name=(EditText) findViewById(R.id.editText1);
    pass=(EditText) findViewById(R.id.editText2);

    String value=getIntent().getStringExtra("username");
    String pass_val=getIntent().getStringExtra("password");
    name.setText(value);
    pass.setText(pass_val);


}
}

Comments

Popular posts from this blog

how to fetch blob image gallery in php html sql

how to save image to pdf in android

How to create album view with fancybox slider view in html php complete code