Application Object

Before we complete this step, here’s the code you need for the previous step.

  1. @Override
  2. public void reset(MenuItem item)
  3. {
  4. totalDonated = 0;
  5. amountTotal.setText("$" + totalDonated);
  6. }

In order to keep out application design coherent, we now bring in an ‘Application’ object.

Create a new package called ‘app.main’ and incorporate this class here:

  1. package app.main;
  2. import android.app.Application;
  3. import android.util.Log;
  4. public class DonationApp extends Application
  5. {
  6. @Override
  7. public void onCreate()
  8. {
  9. super.onCreate();
  10. Log.v("Donation", "Donation App Started");
  11. }
  12. }

Application objects need to be references in the AndroidManifest.xml - at the very top as ‘andorid:name’

  1. <application
  2. android:allowBackup="true"
  3. android:icon="@drawable/ic_launcher"
  4. android:label="@string/app_name"
  5. android:theme="@style/AppTheme"
  6. android:name="app.main.DonationApp">

Make sure the ‘Donation App Started’ appears in the logs to verify that it has actually been engaged correctly, when you launch the app.