Recent Notes
Displaying keyword search results 101 - 110
Created by alfa on June 01, 2011 13:08:36
Last update: June 01, 2011 13:08:36
Code:
public class SplitTest {
public static void...
Output:
Split 1:
'a'
' b '
' c '
'd '
S...
Created by freyo on May 31, 2011 14:45:29
Last update: May 31, 2011 14:47:35
Create BroadcastReceiver class (implement onReceive ):
import android.content.*;
import android.net.Ur...
Declare receiver with intent filter in AndroidManifest.xml :
<receiver android:name="PackageChangeReceiver">
...
In order to receive the broadcasts, the data element is required in addition to the action elements in the intent filter.
When a package is being replaced, the Android system actually broadcasts three intents (in this order):
ACTION_PACKAGE_REMOVED
ACTION_PACKAGE_ADDED
ACTION_PACKAGE_REPLACED
To tell that that an ACTION_PACKAGE_REMOVED or ACTION_PACKAGE_ADDED intent is received as the result of a package being replaced (instead of plain add or remove), check the EXTRA_REPLACING flag:
boolean replacing = intent.getBooleanExtra(Intent....
Created by alfa on May 27, 2011 11:19:29
Last update: May 31, 2011 07:56:26
This is a utility to convert a string value to one of the primitive type values. It is useful in Java reflection code where the value comes in as a string (e.g., from XML parsing), and the type of the value cannot be decided until runtime.
import java.util.*;
import java.lang.reflect.*;...
Note: This method can be extended to convert string to more complex types by writing a converter for the destination type. For example, to convert string to date:
public class DateConverter {
public static ...
Usage:
Date d = (Date) ConvertUtil.convert("10/12/2010", ...
Created by alfa on May 27, 2011 15:46:44
Last update: May 27, 2011 15:46:44
Example code:
import java.lang.reflect.*;
public class Co...
Created by alfa on May 27, 2011 15:21:55
Last update: May 27, 2011 15:21:55
The class java.lang.Package provides a static method to get a package by name: Package.getPackage() .
Example code:
public class GetPackageInfo {
public static...
Created by alfa on May 26, 2011 20:20:50
Last update: May 26, 2011 20:20:50
You would never have guessed it. The test is: Modifier.isStatic(method.getModifiers()) !
Example code:
import java.lang.reflect.Method;
import java.la...
Created by alfa on May 24, 2011 14:52:53
Last update: May 26, 2011 19:52:12
import java.lang.reflect.Method;
public cla...
Created by alfa on May 26, 2011 14:23:33
Last update: May 26, 2011 14:25:42
For Java arrays, the class name is [ followed by an encoded name of the element class. The number of [ characters represents the number of dimensions of the array. The class name encoding is following:
Element Type Encoding
boolean Z
byte B
char C
class or interface L classname;
double D
float F
int I
long J
short S
Example:
public class ClassNameEncoding {
public sta...
Created by alfa on May 26, 2011 13:35:52
Last update: May 26, 2011 13:35:52
Class.isAssignableFrom() returns true only if the argument is identical to the current class or is a subclass of the current class.
Example:
public class AssignableTest {
public static...
Even though an int can be assigned to an Integer and vice versa through auto-boxing, isAssignableFrom returns false when called one way or the other.
// This compiles and runs. But isAssignableFrom() ...
Created by alfa on May 25, 2011 21:17:18
Last update: May 25, 2011 21:18:04
The Java regex expression \B matches a non-word boundary, which is anything other than a word boundary.
import java.util.regex.*;
public class NonW...
Output:
p1 match: word at 40
p1 match: word at 83
...