Use Bundle
to pass Strings
between activities
private Button b1;
static EditText et;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et = (EditText)findViewById(R.id.pass);
b1 = (Button)findViewById(R.id.clickhere);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String pass = et.getText().toString();
if(pass.equals(getString(R.string.Ronnie)) || pass.equals(getString(R.string.Ankita)))
{
Intent myIntent = new Intent(MainActivity.this, Thought.class);
myIntent.putExtra("pass",pass);
startActivity(myIntent);
}else{
Toast.makeText(getApplicationContext(),"Not for you",Toast.LENGTH_SHORT);
}
}
});
}
get data like
public class Thought extends Activity {
public ImageView iv;
static String s1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_thought);
iv = (ImageView)findViewById(R.id.imageView);
final Intent intent = getIntent();
Bundle bundle = intent.getExtras();
if(bundle != null){
String pass = bundle.getString("pass");
if(pass.equals(getString(R.string.Ronnie)))
{
iv.setImageResource(R.drawable.ronniel);
}
else if(pass.equals(getString(R.string.Ankita)))
{
iv.setImageResource(R.drawable.ankitat);
}
}else
{
iv.setImageResource(R.drawable.subha);
}
}
}
1
solved String not compared in the second activity