FAQ

[android-developers] Embedding Activity from different Application, both applications using same library causing ClassCastException on inflating views

Smill
Sep 30, 2011 at 5:05 pm
Hi

I have 2 applications: APP1 (with activity Act1), APP2(with activity
Act2) and some android library LIB used in both applications with
"uses-library" in AndroidManifest.xml.

I'm trying to embed Act2 into Act1 using ActivityGroup. After
inflating Act2's layout I'm trying to get some view form the resulting
view object but got ClassCastException
(findViewById(R.id.some_view_id).getClass().getName() is identical
with the class I want to cast to).
I'm aware Act1 and Act2 are running in the same process and they are
using different classloaders to load classes: App1CL and App2CL. But I
don't understand why the LayoutInflater is using App1CL to instantiate
the view classes.

The problem: I can't use the shared libraries in this scenario
My question: Does anyone know some workarround for this problem? Maybe
there is a way to instruct LayoutInflater to load view classes using
some other classloader, maybe Thread's contextClassloader?

I'm on Gingerbread so I don't have Fragments, I don't know if the
problem is reproductible there with fragments.
I found this discussion on this group:
http://groups.google.com/group/android-developers/browse_thread/thread/77f371c85e47142c?
It seems nobody wants to add relevant information about this.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
reply

Search Discussions

2 responses

  • Mark Murphy at Sep 30, 2011 at 5:16 pm

    On Fri, Sep 30, 2011 at 10:00 AM, smill wrote:
    I'm on Gingerbread so I don't have Fragments
    Sure you do, via the Android Compatibility Library:

    http://android-developers.blogspot.com/2011/03/fragments-for-all.html

    --
    Mark Murphy (a Commons Guy)
    http://commonsware.com | http://github.com/commonsguy
    http://commonsware.com/blog | http://twitter.com/commonsguy

    _The Busy Coder's Guide to *Advanced* Android Development_ Version 2.0
    Available!

    --
    You received this message because you are subscribed to the Google
    Groups "Android Developers" group.
    To post to this group, send email to android-developers@googlegroups.com
    To unsubscribe from this group, send email to
    android-developers+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/android-developers?hl=en
  • Smill at Oct 1, 2011 at 7:26 am
    Thanks Mark,
    Using fragments would require to rewrite lot of code so for me it's
    not a solution. I'll try to reproduce this problem with fragments
    anyway.

    I'm still waiting for an answer about the LayoutInflater job. It seems
    my problem and the other refered in my previous post are related. If
    we run 2 apps and use same library from both apps, only the first
    app's layout resources inflated from library have view instantiated
    correctly. The second activity gets the views from library
    instantiated by the first app's classloader.

    br,
    smill
    On 30 sep., 20:15, Mark Murphy wrote:
    On Fri, Sep 30, 2011 at 10:00 AM, smill wrote:
    I'm on Gingerbread so I don't have Fragments
    Sure you do, via the Android Compatibility Library:

    http://android-developers.blogspot.com/2011/03/fragments-for-all.html

    --
    Mark Murphy (a Commons Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy

    _The Busy Coder's Guide to *Advanced* Android Development_ Version 2.0
    Available!
    --
    You received this message because you are subscribed to the Google
    Groups "Android Developers" group.
    To post to this group, send email to android-developers@googlegroups.com
    To unsubscribe from this group, send email to
    android-developers+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/android-developers?hl=en

Related Discussions

Discussion Navigation
viewthread | post

2 users in discussion

Smill: 2 posts Mark Murphy: 1 post