Hallo,
Is there a reason why the Thread class in the SDK LunarLander and JetBoy examples are not each in a separate java file, rather than being inside the View file?
It would make things a bit clearer, IMHO. Am I missing something?
Frink
They are bother inner classes so it allows them to share global variables
Look at ReplicIsland source for a different example..
but the first step in thinking about is what is the DVM behavior concerning a class when GC operates between a class in a separate file and a class in another class file..
Related
I want to use this class to render the animation in the word thread,
But now I can't find this class, who can tell me why this class was deleted?
question why it was removed should be answered by someone from Android team. probably they just refactored some internal animation utils due to new possibilities...
you can always copy-paste this class source and paste into your project (with different name just in case), you probably should find workaround for FallbackLUTInterpolator usage (or just remove related items, supplying different Interpolator in this place, eg. linear)
SOURCE
Context: "This is an abstract class whose implementation is provided by the Android system"
I was thinking of deriving it to include some handy methods, but I'm not sure what to make of the above line. Any thoughts?
The problem is that things like Activity are indirect subclasses--they won't see your additional functionality.
If your use is isolated and that's okay, then it doesn't matter--just something to be aware of, which sounds like it'd reduce the effectiveness of extending at that level, considering how much stuff extends it.
General question:
Is it possible to use a ClassLoader to replace a pre-loaded (by the system, e.g. found in Android's %android%/frameworks/base/preloaded-classes file) class?
Specific:
I am attempting to use the DexClassLoader to replace a class found in android.net.* before creating a WebView in my application. I can get a Class object, but getMethods() for example gives me an array I'd expect in the unmodified/original class implementation. Is this due to the preloaded-classes system?
Basic setup & pseudo code:
Modify android.net.* class, adding a few test methods/etc.
Compile and end up with classes.dex
jar cf mytest.jar classes.dex
Include mytest.jar in APK assets
Create DexClassLoader and get Class via loadClass()
getMethods() on Class object returns an array I'd expect to see without modifications present in #1
I can provide more details on the setup I'm using and code if needed.
No you can not. WebView is part of the boot class path, and thus the base class loader. There is nothing you can do to make it use classes in another class loader. In fact, it has already been loaded and linked to the classes it uses before your app is even launched (as part of the zygote process pre-initialization).
I have a common library where I've put classes that are used between multiple Android projects. However, now I encountered a situation where I have to make minor changes to the functionality of the class in one project. How should I organize the classes, keeping in mind easy readability of code and future extension possibilities?
Should I
Extend the class (MyClass) with modifications that are special to the subproject (MyClassSub extends MyClass)? What about if I have references to MyClass in the library classes, but in this special subproject MyClassSub should be called?
Have switch OR if clauses for each special part in the class file? And then pass some variable to the class?
Some other option?
This is probably a trivial question, but I am quite new to java and can't quite figure it out.
Definately 1.
Create a library (jar) containing the base class, and then use that jar in the projects that need its base functionality. Each project should provide the specialized class that extends the base.
If the new functionality is specific to the one project, I would avoid putting the functionality in the library. Go with a subclass or a replacement class. If later you find that this extended behavior is more widely usable, you can migrate it to the library (perhaps creating an entire new version of the library, much in the same way that the Java API evolves.)
Unfortunately the answer is "it depends."
Specifically, a class hierarchy should be designed such that the behavior of the base class holds for all subclasses of the class. One way to look at this is to say that the subclass may expand the behavior of the base class. The corollary is that a subclass should not restrict the behavior of the base class. So a Square IS NOT A Rectangle.
Also consider "favor composition over inheritance" unless the base class is specifically designed for inheritance, as a change to the base class might BREAK the subclass.
Have fun!
I'm trying to convert a Java Program to Android. I created a new xml Interface and most of the core logic is still running but since Swing is not present in Android i'm missing the class javax.swing.tree.DefaultMutableTreeNode in particular.
Is there an easy way to replace the class with something equivalent in Android?
Thanks in advance!
Taber
There is no Tree view on Android, so there is no directly comparable class.
But, if you need to use a tree-like data structure to display it's data in UI, for example in ExpandableListView, then you can use CursorTreeAdapter.