ClassLoader icon indicating copy to clipboard operation
ClassLoader copied to clipboard

Question about AppCompatActicity

Open sleeepapnea opened this issue 6 years ago • 3 comments

I read the comments of the last issue. However, MainActivity of Resource1 is extends Activity, and MainActivity of Resource2 is extends AppCompatActivity. And these things work well. How is that possible?

sleeepapnea avatar May 16 '19 02:05 sleeepapnea

We have 3 MainActivity in ClassLoader, Resource1 and resource2.

You could import the same dependencies such as com.android.support:appcompat-v7 in both Resource1 and Resource2, and it works well because the ClassLoader app runs them on two separate processes.

But if you try to import the same dependencies in ClassLoader app and whatever apks, this will lead to ClassCastException errors: java.lang.ClassCastException: android.support.v7.widget.ContentFrameLayout cannot be cast to android.support.v7.widget.ContentFrameLayout

In Java, the way you compare objects is to check their names and class loaders. Those two classes have exactly the same name, but loading from different class loaders. That's why you can't have AppCompatActivity loaded in ClassLoader app and Resource app at the same time.

Catherine22 avatar May 16 '19 06:05 Catherine22

Hello, I am interested in getting to find solution for this issue too. So, if I understand correctly, if main app would just use simple Activity, the plugin/resource could use AppCompatActivity. So far all my attempts failed with Android got confused with finding AppCompat resources. Trying to use constraint layout library failed too (they have their own R. resources).

redrebel696 avatar May 20 '19 21:05 redrebel696

Exactly.

Catherine22 avatar May 21 '19 01:05 Catherine22