title: Android: get current activity in an extended class
body: <p>In an Android app, each time a new activity is loaded, I want to use text-to-speech to announce the name of the activity. How do I obtain the name of the current activity?</p>
  
  <p>I am creating an application that is to be accessible to blind people. I have created an <code>AccessibleActivity</code> class which extends <code>Activity</code>; the other activity classes that I create extend that.</p>
  
  <p>Here is a barebones version of the <code>AccessibleActivity</code> class: </p>
  
  <pre><code>package com.example;
  
  import android.app.Activity;
  import com.example.TTS;
  
  public class AccessibleActivity extends Activity {
  
      TTS tts = new TTS(); // See below
  
      @Override
      public void onResume() {
          tts.resume(getApplicationContext());
          super.onResume();
      }
  
      @Override
      public void onPause() {
          tts.pause();
          super.onPause();
      }
  }
  </code></pre>
  
  <p>Here is the <code>TTS</code> class used by the <code>AccessibleActivity</code> class:</p>
  
  <pre><code>package com.example;
  
  import android.content.Context;
  import android.speech.tts.TextToSpeech;
  import java.util.Locale;
  
  public class TTS {
  
      TextToSpeech ttobj;
  
      public void resume(Context context) {
          ttobj = new android.speech.tts.TextToSpeech(context,
                  new android.speech.tts.TextToSpeech.OnInitListener() {
  
                      @Override
                      public void onInit(int status) {
                          if (status != android.speech.tts.TextToSpeech.ERROR) {
                              ttobj.setLanguage(Locale.UK);
  // THIS IS WHERE I WANT TO USE THE NAME OF THE ACTIVITY, INSTEAD OF "Welcome"
                              speakText("Welcome");
                          }
                      }
                  });           
      }
  
      public void pause() {
          if (ttobj != null) {
              ttobj.stop();
              ttobj.shutdown();
          }
      }
  
      public void speakText(String toSpeak) {
          ttobj.speak(toSpeak, android.speech.tts.TextToSpeech.QUEUE_FLUSH, null);
      }
  }
  </code></pre>
  
  <p>For example, suppose this activity is loaded...</p>
  
  <pre><code>package com.example;
  
  public class BrailleActivity extends AccessibleActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_braille);
      }
  }
  </code></pre>
  
  <p>... and that the <code>strings.xml</code> file contains an entry like this:</p>
  
  <pre><code>&lt;string name="activity_braille"&gt;Learn to type in Braille&lt;/string&gt;
  </code></pre>
  
  <p>How can I get the identifier <code>activity_braille</code> at some point in or after the <code>onResume()</code> method in the <code>AccessibleActivity</code> class, so that the appropriate string can be used in the <code>onInit()</code> method of the <code>TextToSpeech</code> object?</p>