Thursday, August 11, 2011

Expiry of Default Debug Key

Today, when I tried to build and test my new android application on my Samsung Nexus S., a sparking red error popup in my problems window of Eclipse. The error message shows as:
Description Resource Path Location Type Error generating final archive: Debug Certificate expired on 8/10/11 8:48 PM Sample_10_3 Unknown Android Packaging Problem
I tried to delete this error by press "Delete", but the new error message shows me I don't have the respective .apk file, which caused by failed to build my application.

The problem for these error messages is my default debug key is expired, which demonstrates I have been an Android Developer for One Year. It reminds me the first HelloWorld application I tried with the emulator last year. It's in Bin's Bio-Medical Engineering class. My mind was out of class, which is filled with the question "Why my helloworld application never works." (Actually the reason is I never have the patient for that running out.)  How time flies.

The solution for this problem is: delete the debug.keystore, which is under my ~/.android/ directory. For different OS, the dir might be different.

For reference,

Friday, August 5, 2011

Context Menu:

Context Menu is a floatinglist of menu items that appears when the user touches and holds a view that's registered to provide a context menu. It's conceptually similar to the menu displayed when the user performs a "right-click" on a PC, which provides the user access to actions that pertain to a specific item in the user interface. On Android, a context menu is displayed when the user performs a "long press" (press and hold) on an item. It could created for any views.

To create a context menu, you should:
  1. Have the view you need to attach the context menu, and registered these views by call registerForContextMenu();
    E.g. registerForContextMenu(findViewById(;
  2. Define the appearance of the context menu;
    Override the function onCreateContextMenu().
    There two ways to create the context menu by using this function:
    • Using predefined menu xml file;
      public void onCreateContextMenu(ContextMenu menu, View v,
                                      ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(, menu);
       Here the is the menu information you need to create the menu.
    • Dynamically create menu, and add items to the menu;
      public void onCreateContextMenu(ContextMenu menu, View v,
                                      ContextMenuInfo menuInfo) {
        if(v == findViewById({ menu.add(0, Menu1, 0. R.string.mi1) ...}
        else if(v == findViewById({...}
  3. Define the behavior of the context menu
    Override the function onContextItemSelected().
    public boolean onContextItemSelected(MenuItem item) {
      AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
      switch (item.getItemId()) {
        return true;
        return true;
        return super.onContextItemSelected(item);