I need to setImageResource in Activity A's ImageView after clicking a button in Activity B. I'm trying to do this creating a public static ImageView.
Here's the code of Activity A:
public class ActivityA extends Activity {
public static ImageView image;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activityA);
image = (ImageView) findViewById(R.id.image);
}
Here's the code of Activity B:
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View button) {
if(editText.getText().toString().equalsIgnoreCase("myText")) {
ActivityA.image.setImageResource(R.drawable.other_image);
Intent act2= new Intent(ActivityB.this,ActivityA.class);
startActivity(act2);
}
});
}
I can't understand why my App crashes after button is clicked (it works if I remove "activityA.image.setImageResource(R.id.other_image)
" ) so the problem must be here. Should I write something else in ActivityA.class?
Thank you for every possible solution and
sorry for my bad english.