I have 2 activities as follows: The first activity (AddActivity.java activity_add.xml) contains Image button:
<ImageButton
android:layout_width="match_parent"
android:layout_height="120dp"
android:onClick="onClickImageButton"
android:id="@+id/imageButtonProfile"/>
The second activity: (EnlargeImageActivity.java - activity_enlarge_image.xml) contains another image button:
<ImageButton
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/enlargeImageButtonProfile"
android:onClick="onClickImageButton"/>
When creating the second activity (EnlargeImageActivity) I want to put the image from first activity and put it in the second activity. I read here:
How can I pass an Buttom ID to other Activity
that it is not recommend to pass images between 2 activities.
So how can I get the ImageButton of the first activity in the creation of the second activity ?
I cant call findViewById(R.id.imageButtonProfile);
because I'm getting null
I have tried to use:
ImageButton ib=(ImageButton)findViewById(R.id.imageButtonProfile);
Intent intent = new Intent(this, EnlargeImageActivity.class);
intent.putExtra(SRC_IMG_BUTTON_ID, ib.getId());
startActivity(intent);
and in EnlargeImageActivity.java:
Intent intent = getIntent();
int srcId = intent.getIntExtra(AddActivity.SRC_IMG_BUTTON_ID, 0);
ImageButton ibSrc =(ImageButton)findViewById(srcId);
but same results ibSrc is null