Friday, March 7, 2014

Android Application Life Cycle

Android Application Life Cycle


The Android application life cycle is unique in that the system controls much of the life cycle of the application. All Android applications, or Activities, are run within their own process. All of the running processes are watched by Android and, depending on how the activity is running (this is, a foreground activity, background activity, and so forth), Android may choose to end the activity to reclaim needed resources.
Some of the specific methods called during the life cycle of an android activity are
  • onCreate
  • onStart
  • Process-specific events (for example: launching activities or accessing a database)
  • onStop
  • onDestroy
Following the same logic as other application life cycles, an Android application is created, the processes are started, events are fired, processes are stopped, and the application is destroyed. Though there are a few differences, many application developers
should be comfortable with the steps in the life cycle.

Java Packages & Interfaces

Java Packages & Interfaces

Packages are containers for classes that are used to keep the class name space compartmentalized. For example, a package allows you to create a class named List, which you can store in your own package without concern that it will collide with some other class named List stored elsewhere.
Through the use of the interface keyword, Java allows you to fully abstract the interface from its implementation. Using interface, you can specify a set of methods which can be implemented by one or more classes. The interface, itself, does not actually define any implementation.
This is the general form of the package statement:

package package_name;

A Short Package Example

Keeping the preceding discussion in mind, you can try this simple package:
// A simple package
package MyPack;
class Balance {
String name;
double bal;
Balance(String n, double b) {
name = n;
bal = b;
}
void show() {
if(bal<0 font="">
System.out.print("--> ");
System.out.println(name + ": $" + bal);
}
}
class AccountBalance {
public static void main(String args[]) {

Balance current[] = new Balance[3];
current[0] = new Balance("K. J. Fielding", 123.23);
current[1] = new Balance("Will Tell", 157.02);
current[2] = new Balance("Tom Jackson", -12.33);
for(int i=0; i<3 current="" font="" i="" show="">
}

}