I know this is common to ask, but I'm confused about how can I pass the data bitmap Image back to the first activity,when I click the button from first Activity it will goes to the second activity, when the user done filling the signatories it will have the format of bitmap
and pressing save will display the image bitmap back to the first Activity, how can I achieve this?, I tried the following code below but it doesn't display the image, need help
Currently I'm trying this code below to pass from second activity to first activity
but it doesn't work
Bitmap bitmap = signaturePad.getSignatureBitmap();
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.putExtra("imageExample", bitmap.toString());
startActivity(intent);
First Activity
ImageView image;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnNext = (Button) findViewById(R.id.btnNext);
image = findViewById(R.id.imgUri);
//get image from second activity
getImage();
btnNext.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
startActivity(intent);
}
});
}
public void getImage(){
Bundle extras = getIntent().getExtras();
if (extras != null) {
String resultUri = extras.getString("imageExample");
Uri myUri = Uri.parse(resultUri);
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(),myUri);
image.setImageBitmap(Bitmap.createScaledBitmap(bitmap, 374, 500, false));
} catch (IOException e) {
e.printStackTrace();
}
}
}
SecondActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.accomplished_signature);
SignaturePad signaturePad = findViewById(R.id.signature_pad);
Button buttonSignature = findViewById(R.id.btnSubmit);
Button buttonClear = findViewById(R.id.btnClear);
buttonClear.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View v) {
signaturePad.clear();
}
});
buttonSignature.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View v) {
Bitmap bitmap = signaturePad.getSignatureBitmap();
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.putExtra("imageExample", bitmap.toString());
startActivity(intent);
signaturePad.clear();
}
});
}