0

I have looked everywhere for this and I couldn't find any answer.

I am sending data over an intent like this.

MainActivity.java

Intent intent = new Intent(MainActivity.this, SecondActivity.class);
            intent.putExtra("key",Paint.Cap.SQUARE);
            startActivity(intent);

My issue is in retrieving it, I don't know which get method to use and I couldn't find any source online that tells me.

SecondActivity.java

Bundle extras = getIntent().getExtras();

    if(extras !=null)
    {
        if(extras.containsKey("key"))
        {
            Paint.Cap shape = //which method to use here?

        }
    }

If it's something so silly please tell me, I am still a beginner and tried my best to find it on my own.

Thanks.

  • Possible duplicate of [How do I pass data between Activities in Android application?](https://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android-application) – Aleh Maksimovich Oct 22 '17 at 08:33

1 Answers1

1

The key is that Paint.Cap is an enum and so it implements the interface Serializable.

This means that you called the version of putExtra that takes a Serializable.

To get it out again you can do

Paint.Cap shape = (Paint.Cap) extras.getSerializable("key");
Paul Boddington
  • 37,127
  • 10
  • 65
  • 116