1

I have two Activity class one that is holding the value from the class, second the one who is retrieving the value. I am trying to pass the variable to another Activity class via constructor.

Here is the intent in the 1st activity class

  val intent = Intent(activity, IntentContentActivity(quote)::class.java)
                intent.putExtra("intentFragment", i.toString())
                startActivity(intent)

I tried to debug it so I can see if the data has been passed and it does here what it looks like as you can see the Quote@6908 are passed but still return to me this error. Can someone tell me whats going on here?

Caused by: java.lang.InstantiationException: java.lang.Class<ph.com.sdsolutions.colfinancial.app.IntentContentActivity> has no zero argument constructor
  • `val intent = Intent(activity, IntentContentActivity::class.java)` – ADM Apr 05 '18 at 16:56
  • 1
    The issue is actually in your `IntentContentActivity` class. You can't give Activities constructors with arguments. They are instantiated by the operating system. – nukeforum Apr 05 '18 at 16:56
  • oh ok, any idea how can I pass the quote? –  Apr 05 '18 at 17:00
  • thanks for a good explanation @nukeforum –  Apr 05 '18 at 17:01
  • Passing objects between Activities is accomplished either by parcelizing them and putting them in an Intent, or by persisting them (via database or SharedPreferences) and retrieving them once the next Activity starts. – nukeforum Apr 05 '18 at 17:04
  • thank you very much for making it so clear, but last question. I found [this] tutorial and I applied it like this ` val b = Bundle() b.putParcelable("pase",quote);` but it doesn't work (https://stackoverflow.com/questions/2906925/how-do-i-pass-an-object-from-one-activity-to-another-on-android) –  Apr 05 '18 at 17:12
  • @nukeforum you there? –  Apr 05 '18 at 17:27
  • nvm I have solved it Thankyou very much sir @nukeforum ur the best! –  Apr 05 '18 at 17:33

0 Answers0