0

I need to send object from fragment to activity. But it's not working. I tried something like follows.

Fragment; enter image description here

Target class; enter image description here

Adapter method;

enter image description here

Why it's not working? I need your help guys.

  • you are passing adapter position which is integer value in the intent from fragment and in activity you receive it as a serializable ! – Tausif May 23 '21 at 16:23
  • sorry but i didn't understand what are you mean. I use getSerializable because i sending an object. Can you give me example what is not working? – Doğukan Çiftçi May 23 '21 at 16:37
  • you are passing integer value instead of object according to your code. – Tausif May 23 '21 at 16:39
  • https://stackoverflow.com/a/51415489/4785772 Please follow this link, it will help you to understand – Tausif May 23 '21 at 16:41
  • l looked at the link you sent but i cant fix my problem. And you said 'you sending int' but i' m not did that exactly. If you look at the third picture you will see. I sending Datum obejct. getItem method is returning Datum object. – Doğukan Çiftçi May 23 '21 at 16:59
  • Understood now ! There is something wrong with the way you have passed object. can you please log it what datum object return when you call getItem method ? – Tausif May 23 '21 at 17:08
  • I will explain your comment as I understand it. The getItem method is bringing me back to datum. So far everything is normal. But i can't send this object from fragment to activity. İt's says "Cast 2nd parameter to Serizable". When i did(like (Serizable) adapter.getItem(position)) and run it I get Class.Cast.Exception. And it say "Datum cannot be cast to java.io.Serializable". i hope you understand me, i hope i explained it clearly – Doğukan Çiftçi May 23 '21 at 21:23
  • 1
    Datum class needs to implement serializable like that way "public class datum implements Serializable ". Please check your Datum class is implementing serializable correctly way or not. – Tausif May 24 '21 at 04:44

0 Answers0