Keep tts speaking even if get call - android

I made an Android application which uses TextToSpeech and works fine. The only problem is that when i receive call, TextToSpeech stops.
I use some apps like mine and they continue speaking even during received call. How can I do that? Maybe using something like link async?
Thanks!

What happens is that when you receive a call, your app's activity is onPause.
So you should start a background service from your activity and handle textToSpeech from there(the service).
So that even if the activity is paused, textToSpeech continues doing its work.
Here: http://developer.android.com/reference/android/app/Service.html
And a useful tutorial on services: http://www.vogella.com/articles/AndroidServices/article.html

I'm using TextToSpeech on background service (unbind service)

Related

Start a service in Activity to monitor Missed calls

I am trying to do the program to monitor Missed calls. I start a service in Activity, and use BroadcastReceiver in service to monitor Missed calls. How to continue monitor Missed calls after Activity is destroyed?
Now I want to a progress of background to realize this. Thanks in advice.
This is a very good tutorial about service in android:
http://www.vogella.com/articles/AndroidServices/article.html
According to this , your Service will keep working in background until it is stopped explicitly, even if your app is in background or is closed.
Service always keeps running in the background unless you explicitly stop it... Here is a good tutorial that should get you started:
http://mindtherobot.com/blog/37/android-architecture-tutorial-developing-an-app-with-a-background-service-using-ipc/

android correct control of a service

I have a thread (Updater) inside a service (RefreshTasks) that check if there are some updates on the server. Then I have 4 activities that use those data.
But I have a problem in managing this service...
I would like to keep the service active along the whole application, even if the screen goes off. What is the correct practice to manage a service like this? In this moment I start and stop the service every onResume and onPause method of all activities... but this implies that the service will stop when the screen goes off.
Any suggestion?
Thanks AL.
The Service instance continues to run also when your app is paused.
I suggest you to look also this service provided by Google, which is a good solution for push notification in communication between the device and your service:
https://developers.google.com/android/c2dm/
And this is a good tutorial to start with:
http://blog.mediarain.com/2011/03/simple-google-android-c2dm-tutorial-push-notifications-for-android/

Service or Thread or AsyncTask?

I need an advice for my latest app. It will show the user the latest subtitles released, and it will give him a notification in case new subtitles of his favourite series have been released; what should I use to achieve this?
I was thinking to create and run a service which will include a
timer.scheduleAtFixedRate(new TimerTask() {...
but at the same time I really don't know how to make it interact with my app (if the app is opened I don't need any notification but I need to update the GUI).
I could use a thread but I'd like it to run it even after the main activity has been killed...
or I could use a AsyncTask so it would be easier to deal with the Application GUI.
Which solution should I use? I was thinking I should simply use a service (the first solution), but I'm not too sure about it, and furthermore I don't know if there is any way to make a service communicate with an activity periodically...
Thanks for your help.
A service communicating with an activity is called bound service, that's what you should use IMO.
However, you say that when the activity dies, the service should keep running. But if the service is bound to your activity and the activity is dies, the service dies too.
I suggest you to read here about it.
Check and see if you can bind a service to an activity, and when it dies, unbind and let the service continue to run independently.
If you can't, the activity could unbind itself, then start the service independently (with startService rather than bindService).
if you are showing notifications, why not use C2DM messages for communicating with the app. The only thing would be that there would be popups shown to the user even if your app is not running. No need to use threads/services.

Android:Service Activity Start and Stop Control

Hello Android Gurus
For API Level 7 and Above-->
I am badly struck trying to figure out a solution for the following problem:
I have an activity which i would use to Kick start an Service. This is an infinite loop service which can run forever. I would like to disconnect the Service from Activity and at a later point of time i will call the activity again which should tell me the current state of Service and i can Stop the service.
Is something like this possible. Right now my Service is Sticky and i am not able to Close the activity as Service is running for ever and i am also not able to Stop the service from activity.
Code samples would be of great help!!! Thanks in advance...
Multiple questions:
You can disconnect/reconnect from the Service using bind. Unfortunately the best advice to give there is to carefully read the documentation for Service at http://developer.android.com/reference/android/app/Service.html: look carefully at the Local Service example, as it demonstrates what you need to do to bind/unbind to a sticky service.
To stop it, once you've bound you can call stopSelf.
Start the service non sticky from the Activity.
In the service control the flow logically, say calling onStart() to keep it running.
Call onDestroy() when you have to stop.

Can anyone explain the Service setForeground method?

I'd like to know more about the setForeground() method in the Service class.
Can any one explain it in detail?
setForeground() is deprecated, and I think simply does not work on newer versions of Android. You want the newer startForeground() instead.
Quoting myself from one of my books:
However, some services will be missed
by the user if they mysteriously
vanish. For example, the default music
player application that ships with
Android uses a service for the actual
music playback. That way, the user can
listen to music while continuing to
use their phone for other purposes.
The service only stops when the user
goes in and presses the stop button in
the music player activity. If that
service were to be shut down
unexpectedly, the user might wonder
what is wrong.
Services like this can declare
themselves as being part of the
"foreground". This will cause their
priority to rise and make them less
likely to be bumped out of memory. The
trade-off is that the service has to
maintain a Notification, so the user
knows that this service is claiming
part of the foreground. And, ideally,
that Notification provides an easy
path back to some activity where the
user can stop the service.
To do this, in onCreate() of your
service (or wherever else in the
service's life it would make sense),
call startForeground(). This takes a
Notification and a locally-unique
integer, just like the notify() method
on NotificationManager. It causes the
Notification to appear and moves the
service into foreground priority.
Later on, you can call
stopForeground() to return to normal
priority.

Categories

Resources