Diagram of Android Activity Lifecycle (High Resolution) for quick reference

Here is a high resolution diagram (click on the image to open large version) that shows the life cycle of android activity.

It particularly shows how the following Android Activity methods are called during the life cycle of the particular activity.

  1. onCreate()
  2. onStart()
  3. onResume()
  4. onPause()
  5. onRestart()
  6. onStop()
  7. onRestart()

Utility Class For Getting SQL Connection and Closing It

The following is a sample class which you can use as an utility in getting the mysql connections
and closing it (rather than writing the same code again and again to get and close the connection)

/* @author Kushal Paudyal*/
package com.ghumti.kschool.core.database;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

import com.ghumti.fw.domain.KSEntity;

public class KSDBConnection extends KSEntity {
	private String dbUserName = "root";
	private String dbPassword = "";
	private String dbURL = "jdbc:mysql://localhost:3306/";
	private String database = "kschool";
	private String driver = "com.mysql.jdbc.Driver";

	public Connection getConnection() {
		Connection conn = null;
		try {
			Class.forName(driver).newInstance();
			conn = DriverManager.getConnection(getDbURL() + getDatabase(),
					getDbUserName(), getDbPassword());

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			return conn;
		}

	}

	public void closeConnection(Connection dbConnection, String className) {
		try {
			dbConnection.close();
		} catch (SQLException e1) {
			System.out.println(className
					+ ": Could not close database connection");
			e1.printStackTrace();
		}

	}

	/*
	 * Usage Example
	 */
	public static void main(String args[]) throws Exception {
		KSDBConnection ksdb = new KSDBConnection();
		Connection conn = ksdb.getConnection();

		String sqlQuery = "Select * from myTable";
		Statement st = conn.createStatement();
		st.execute(sqlQuery);

		/*
		 * Finally Close the connection The second parameter is just used for
		 * error printing
		 */
		ksdb.closeConnection(conn, KSDBConnection.class.getName());

	}

}

List of valid @suppresswarning annotation parameters in Java for Eclipse and IBM RAD IDE

The following is a list of most of the valid @suppresswarning annotation parameters in Java for Eclipse and IBM RAD IDE. The right column shows what those java annotation parameters are used for.

Annotation Param

Usage

intfNonInherited interface non-inherited method compatibility
javadoc invalid javadoc
localHiding local variable hiding another variable
maskedCatchBlocks hidden catch block
nls to suppress warnings relative to non-nls string literals
noEffectAssign assignment with no effect
null to suppress warnings relative to null analysis
nullDereference missing null check
over-ann missing @Override annotation
paramAssign assignment to a parameter
pkgDefaultMethod attempt to override package-default method
raw usage a of raw type (instead of a parametrized type)
restriction to suppress warnings relative to usage of discouraged or forbidden references
semicolon unnecessary semicolon or empty statement
serial to suppress warnings relative to missing serialVersionUID field for a serializable class
specialParamHiding constructor or setter parameter hiding another field
static-access to suppress warnings relative to incorrect static access
staticReceiver if a non static receiver is used to get a static field or call a static method
super overriding a method without making a super invocation
suppress enable @SuppressWarnings
synthetic-access to suppress warnings relative to unoptimized access from inner classes
tasks enable support for tasks tags in source code
typeHiding type parameter hiding another type
unchecked to suppress warnings relative to unchecked operations
unnecessaryElse unnecessary else clause
unqualified-field-access to suppress warnings relative to field access unqualified
unused to suppress warnings relative to unused code
unusedArgument unused method argument
unusedImport unused import reference
unusedLabel unused label
unusedLocal unused local variable
unusedPrivate unused private member declaration
unusedThrown unused declared thrown exception
uselessTypeCheck unnecessary cast/instanceof operation
varargsCast varargs argument need explicit cast
warningToken unhandled warning token in @SuppressWarnings

 

Here is an usage example. As you can see, the piece of code below does not use any annotations and the code has a yellow underline in the method signature. If you hover around the icon on the left bar of the IDE where there will be warning sign, you will notice that the Eclipse IDE has issued warning saying that this method is never called in the class.

 

But if you put the annotation @SuppressWarning(“unused”), we specifically tell the IDE to ignore the usused methods by suppressing the warnigns. Here is the code after the annotation has been added. Code looks clean, no more annoying warning underline !