ClassLoader
ClassLoader copied to clipboard
Question about AppCompatActicity
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?
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.
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).
Exactly.