• Post Reply Bookmark Topic Watch Topic
  • New Topic

Calling startActivityForResult crashes app  RSS feed

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have an activity(Activity A) and a custom adapter, MyProductsAdapter. In my custom adapter, I would like to call Activity B for result so that Activity A gets the result.

In Activity A:



in MyProductsAdapter:



in MyProductsAdapter's getView():



But the app crashes at the last line. Error message is:  java.lang.ClassCastException: android.support.multidex.MultiDexApplication cannot be cast to android.app.Activity

Please help. If I am unclear, please ask me to elaborate. Thanks.
 
Saloon Keeper
Posts: 4329
108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getApplicationContext() returns the Application, not the Activity.  While both are subclasses of Context, neither is a subclass of the other, so they can't be substituted for one another. If that code runs in an Activity -as you state- you can just use "this" as the first parameter of the MyProductsAdapter constructor.
 
Alan Blass
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,

Thank you for your answer.

I have changed it; it runs. But before Activity B starts, Activity A's onActivityResult() method is called first. Then Activity B starts.

When Activity B finishes, Activity A's onActivityResult() does not get called.

Here is how I end by Activity B:



Am I doing something wrong? Please help. Thanks.
 
Tim Moores
Saloon Keeper
Posts: 4329
108
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure. Does removing "intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);" make a difference?
 
Alan Blass
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,

Yes, it did. Thank you very much for your suggestion.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!