CODE:

public String getTopActivity(Activity activity) {
    ActivityManager am = (ActivityManager)activity.getSystemService(Activity.ACTIVITY_SERVICE);
    ComponentName cn = am.getRunningTasks(1).get(0).topActivity;
    LOG.d("topActivity" + cn.getClassName());
    return cn.getClassName();
}