Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7541171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:49:32+00:00 2026-05-30T07:49:32+00:00

I have an application using TTS very heavily. It’s working fine, but I need

  • 0

I have an application using TTS very heavily. It’s working fine, but I need to tweak it.

I am using a TTS object in every screen and this is not good. I wish I could creat the TTS object just once (like a Singleton) and them, use it throughout all my activities.

Here is the base code for this to work:

    public class SimOuNaoActivity extends Activity implements OnInitListener{
    public TextToSpeech tts;
        private int MY_DATA_CHECK_CODE = 0;


        @Override
        public void onCreate(Bundle savedInstanceState) {

          super.onCreate(savedInstanceState);
    Intent checkIntent = new Intent();
    checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);
    tts.speak("Testing 1,2,3", TextToSpeech.QUEUE_ADD, null);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == MY_DATA_CHECK_CODE) {
        if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
            tts = new TextToSpeech(this, this);
        } else {
            // missing data, install it
            Intent installIntent = new Intent();
            installIntent
                    .setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
            startActivity(installIntent);
        }
    }

}

@Override
public void onInit(int status) {
    if (status == TextToSpeech.SUCCESS) {
        // Toast.LENGTH_LONG).show();
    } else if (status == TextToSpeech.ERROR) {
        // Toast.LENGTH_LONG).show();
    }
}

@Override
public void onDestroy() {
    if (tts != null) {
        tts.stop();
        tts.shutdown();
    }
    super.onDestroy();
       System.gc();
    }

    }

What is the correct approach to have the TTS object available in all my activities? Have in mind that it uses some methods like startActivityForResult, etc… so… I would like to know what I can do to make this work fine.

Can anyone help me, please?

Any help is appreciatted!

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T07:49:33+00:00Added an answer on May 30, 2026 at 7:49 am

    Have a look here to share stuff between activities and program with nicer design in android :
    Intent.putExtras size limit?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm certainly no Ruby developer but I have an application on my server using
I have the application using an .ico image for the taskbar and window, but
I have an application written in Delphi 2006 that was working fine in Windows
I have an application using jython2.1 and I need to run external applications, (lets
I have my application using jQuery heavily. The problem is that we started with
I have a very weird problem. Have an application using Hibernate and spring.I have
I have application using Android 2.1 which utilize LocationManager to get the altitude. But
I have an application using the MySQL .Net connection but for some reason i'm
I have an application using Tomcat/Spring 3/JPA/Hibernate but my merges do not commit to
I have an application using a MongoDB database and am about to add custom

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.