0

I have coded an automatic messaging application in android. It sends messages automatically at a user specified date and time, including repetition and time interval. But the problem I am facing is that since I have used threads for sleeping upto the specified time my app screen goes blank while the threads are in sleeping state. Please suggest how to deal with that???

Captain Obvlious
  • 19,754
  • 5
  • 44
  • 74

1 Answers1

1

If the app sends messages at user specified time and date, i would suggest using AlarmManager and Service to do the job instead of having Threads that sleep. This way your app doesnt have to be "visibly" running to the user to do the "cron" job.

JanBo
  • 2,925
  • 3
  • 23
  • 32
  • oh thankyou... but I am not yet familiar with using services... can you please give an example or suggest a link... Thankyou – user2685528 Oct 02 '13 at 16:12
  • Here are some examples: http://stackoverflow.com/questions/8321443/how-to-start-service-using-alarm-manager-in-android , http://stackoverflow.com/questions/3052149/using-alarmmanager-to-start-a-service-at-specific-time , http://androidsamplecodes4u.blogspot.com/2012/08/start-service-with-alarm-manager-android.html .... this is a good tutorial on just services http://www.vogella.com/articles/AndroidServices/article.html . Also read about services and alarm managers on developer.android to get the whole picture, it will be of good use to you. – JanBo Oct 03 '13 at 10:36
  • Here are the links for official doc: http://developer.android.com/guide/components/services.html , http://developer.android.com/reference/android/app/AlarmManager.html ...and a tutorial on alarm managers: http://www.techrepublic.com/blog/android-app-builder/use-androids-alarmmanager-to-schedule-an-event/ ...dont be intimidated with the amount of info you have to read, take 2 days to read and try out alarm managers and services and you will get the whole picture and thus be able to make everything you need with ease. – JanBo Oct 03 '13 at 10:39