Most visited

Recently visited

Added in API level 14

BaseDexClassLoader

public class BaseDexClassLoader
extends ClassLoader

java.lang.Object
   ↳ java.lang.ClassLoader
     ↳ dalvik.system.BaseDexClassLoader
Known Direct Subclasses


Base class for common functionality between various dex-based ClassLoader implementations.

Summary

Public constructors

BaseDexClassLoader(String dexPath, File optimizedDirectory, String librarySearchPath, ClassLoader parent)

Constructs an instance.

Public methods

String findLibrary(String name)

Returns the absolute path name of a native library.

String toString()

Returns a string representation of the object.

Protected methods

Class<?> findClass(String name)

Finds the class with the specified binary name.

URL findResource(String name)

Finds the resource with the given name.

Enumeration<URL> findResources(String name)

Returns an enumeration of URL objects representing all the resources with the given name.

Package getPackage(String name)

Returns package information for the given package.

Inherited methods

From class java.lang.ClassLoader
From class java.lang.Object

Public constructors

BaseDexClassLoader

Added in API level 14
BaseDexClassLoader (String dexPath, 
                File optimizedDirectory, 
                String librarySearchPath, 
                ClassLoader parent)

Constructs an instance.

Parameters
dexPath String: the list of jar/apk files containing classes and resources, delimited by File.pathSeparator, which defaults to ":" on Android
optimizedDirectory File: directory where optimized dex files should be written; may be null
librarySearchPath String: the list of directories containing native libraries, delimited by File.pathSeparator; may be null
parent ClassLoader: the parent class loader

Public methods

findLibrary

Added in API level 1
String findLibrary (String name)

Returns the absolute path name of a native library. The VM invokes this method to locate the native libraries that belong to classes loaded with this class loader. If this method returns null, the VM searches the library along the path specified as the "java.library.path" property.

Parameters
name String: The library name
Returns
String The absolute path of the native library

toString

Added in API level 1
String toString ()

Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Returns
String a string representation of the object.

Protected methods

findClass

Added in API level 1
Class<?> findClass (String name)

Finds the class with the specified binary name. This method should be overridden by class loader implementations that follow the delegation model for loading classes, and will be invoked by the loadClass method after checking the parent class loader for the requested class. The default implementation throws a ClassNotFoundException.

Parameters
name String: The binary name of the class
Returns
Class<?> The resulting Class object
Throws
ClassNotFoundException

findResource

Added in API level 1
URL findResource (String name)

Finds the resource with the given name. Class loader implementations should override this method to specify where to find resources.

Parameters
name String: The resource name
Returns
URL A URL object for reading the resource, or null if the resource could not be found

findResources

Added in API level 1
Enumeration<URL> findResources (String name)

Returns an enumeration of URL objects representing all the resources with the given name. Class loader implementations should override this method to specify where to load resources from.

Parameters
name String: The resource name
Returns
Enumeration<URL> An enumeration of URL objects for the resources

getPackage

Added in API level 1
Package getPackage (String name)

Returns package information for the given package. Unfortunately, instances of this class don't really have this information, and as a non-secure ClassLoader, it isn't even required to, according to the spec. Yet, we want to provide it, in order to make all those hopeful callers of myClass.getPackage().getName() happy. Thus we construct a Package object the first time it is being requested and fill most of the fields with dummy values. The Package object is then put into the ClassLoader's package cache, so we see the same one next time. We don't create Package objects for null arguments or for the default package.

There is a limited chance that we end up with multiple Package objects representing the same package: It can happen when when a package is scattered across different JAR files which were loaded by different ClassLoader instances. This is rather unlikely, and given that this whole thing is more or less a workaround, probably not worth the effort to address.

Parameters
name String: the name of the class
Returns
Package the package information for the class, or null if there is no package information available for it

Hooray!