This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • 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
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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: 5229
143
  • 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: 5229
143
  • 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.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!