0

I'm new here, and I just learned how to code an Android application.

Right now, I want to make an Application with Droid Fu library (which is a good library but has a lack of documentation and examples). I'm facing a problem with my handleApplicationClosing function. The problem occurs when I press the back button on my application, which mean the application closing (because I just try with only 1 activity for my testing application with droid fu).

After many tries to debug the program, I found the error occurred when my code reaches this function:

static void handleApplicationClosing(final Context context, int keyCode) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        ActivityManager am = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);
        List<RunningTaskInfo> tasks = am.getRunningTasks(2);

        RunningTaskInfo currentTask = tasks.get(0);
        RunningTaskInfo nextTask = tasks.get(1);

        // if we're looking at this application's base/launcher Activity,
        // and the next task is the Android home screen, then we know we're
        // about to close the app
        if (currentTask.topActivity.equals(currentTask.baseActivity)
                && nextTask.baseActivity.getPackageName().startsWith("com.android.launcher")) {
            DroidFuApplication application = (DroidFuApplication) context
                    .getApplicationContext();
            application.onClose();
        }
    }
}

on this line:

 DroidFuApplication application = (DroidFuApplication) context
                    .getApplicationContext();

The error code was:

java.lang Class ClassCastException

What does this mean?

Zoot
  • 2,217
  • 4
  • 29
  • 47
siryu88
  • 3
  • 1

1 Answers1

1

I never used DroidFu, but make sure you've added next line to you AndrodiManifest.xml:

<manifest ...>
   ...
   <application .... android:name="com.github.droidfu.DroidFuApplication">
      ...
   </application>
   ...
</manifest>
inazaruk
  • 74,247
  • 24
  • 188
  • 156
  • okay, thanks, I'll try when I get home, and I'll rate you if this works.. may thanks.. – siryu88 Dec 14 '11 at 08:52
  • okay.. it's works.. thank you so much inazaruk. Sorry I Can't vote for you, this site tell me to have 15 reputation first. but thank you verymuch... – siryu88 Dec 14 '11 at 22:58