• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

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: 4864
117
  • 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: 4864
117
  • 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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!