Tuesday, March 6, 2012

Expires ADT Debugging Certificate

Some days ago I had a problem, I was developing an application for Android using Eclipse and ADT on Windows-7. I found the following error:

[2012-02-25 14:43:10 - androidVNC]Error generating final archive:
Debug certificate expired on 2/24/12 2:53 PM!

I solved it with the following steps:
  • Open my user's profile directory "C:\Users\ali-hassan"
  • In this directory I found the directory ".android "
  • I delete  "debug.keystore" file from it.
  • I restarted eclipse again and build my project, it would create new certificate automatically.
Thats all for the debug certificate expiration issue.

Monday, September 26, 2011

AIDL (Android Interface Definition Language)

AIDL is an interface definition language like other IDLs Languages. It support in Anroid the interface between two different process communication. It said remote method if a service in other application or process defines a method and client a using Activity or service. Remote method always are written  in Android Service.

There are some simple steps to achieve this task:

  • Create a aidl file.
package com.aidl.test;

interface IRemoteService {
int counter();
        void printMyVal(String val);
}

As it will be saved the ADT plugin generate a java file in gen folder with its package name.

  • Your remote service must implement these method
            1- int counter();
            2- void printMyVal(String val);

@Override
public IBinder onBind(Intent intent) {
return new IAdditionService.Stub() {
@Override
public int counter() throws RemoteException {
return counter;
}

@Override
public void printMyVal(String val){
System.out.println(val);
}

};
}

  • From the client activity or service you should create a class which will implements ServiceConnection interface.
class RemoteServiceConnection implements ServiceConnection {

@Override
public void onServiceConnected(ComponentName name, IBinder aService) {
  service = IRemoteService .Stub.asInterface(aService);  
}

@Override
public void onServiceDisconnected(ComponentName name) {
service = null;
}
}

  • You should create a method init, where you will initiate the connection and bind the remote service.
private void initService(){
    connection = new AdditionServiceConnection();
    Intent i = new Intent();
    i.setClassName("com.aidl.test", com.aidl.test.AdditionService.class.getName());
    boolean ret = bindService(i, connection, BIND_AUTO_CREATE);
    Log.i("Create", "Bind service : "+ret);
    }

  • You need another method release where you release you connection with the service and make this connection null so memory can be freed.
private void releaseRemoteService(){
    if(connection!=null){
    unbindService(connection);
    connection = null;
    Log.i("Create", "Unbind Service");
    }
    }

  • As you will call init method it create a connection and give an object of the service connection which is declare in RemoteServiceConnection method onServiceConnected.
  • Through this object you can call all the remote methods.
  • connection object should be RemoteSercieConnection method and Service object should be IRemoteService reference.
  • onDestroy method you should call the realseRemoteService method.
Its so simple. :)
For further details you should go to http://developer.android.com/guide/developing/tools/aidl.html and read more about AIDL.

Sunday, August 28, 2011

Stacktrace for the Java


final Writer result = new StringWriter();
   final PrintWriter printWriter = new PrintWriter(result);
   e.printStackTrace(printWriter);
   String stacktrace = result.toString();
   Report += stacktrace;
 
   Report += "\n";
   
 
   // If the exception was thrown in a background thread inside
   // AsyncTask, then the actual exception can be found with getCause
   Throwable cause = e.getCause();
   if(cause!=null){
        Report += "Cause : \n";
       
        Report += "======= \n";
   }

   while (cause != null) {
    cause.printStackTrace(printWriter);
    Report += result.toString();
    cause = cause.getCause();
   }
   printWriter.close();