tags:

views:

55

answers:

1

Hello ,

I want to write an app to send an sms from a shortcut on a home screen. That is all.

I just can't understand within the framework how I can write such an app. Here's what I've tried so far and what my ideas are:

  1. I wrote an activity that sends an sms using SmsManager within the onCreate() however, this just keeps on sending messages even though the code is not in a loop. I realise I must be not be using an activity the way it's designed to be used. The android application fundamentals article says an activity is for displaying a screen or gui, but I don't need a gui. I just don't know what component I need to to use.

A service? no, because I don't need something running forever in the background. An activity? I guess no because I don't need a gui.

I had an idea to create a broadcast receiver which would respond to a broadcast, so my sens smsm code would be in there ready to send when it receives the signal. But how do i send the signal from an app shortcut on the home screen? What would be the entry point of the app.

I'm just really confused, I've read the tutorials and the app fundamentals and searched forums and not found the answer. There's is just a big gap in my knowledge of the android framework that needs filling I guess, once it clicks I'll be fine but I'm just stuck right now.

Thanks people.

+2  A: 

Service does not have to run forever. You can control how long it works in the background, you can even create Service that will shoot once and disappear. Suggestion:

  • from your shortcut (app icon) start Activity. That will be activity with translucent background. To achieve that skip line setContentView() and define theme

@android:style/Theme.Translucent

in your AndroidManifest.xml. This way you will avoid black screen flash at Activity startup.

  • from that Activity start Service and call finish() on that Activity
  • perform SMS sending (you already know how) from Service. Maybe, you do not even need Service, you can send SMS from the translucent Activity.
  • call stopSelf() from your Service immediatelly or after some short timeout (wait for SMS sending result).

All described can be done smoothly through Widget framework. In that case you can even have custom button user may press on. So, that would be another approach.

Desiderio
Thanks for you reply.
Timothy
Whoops, I was trying a new line and it added a comment. Anyway...You say from my shortcut, well in actual fact that would be my app (with its own icon I guess) When the app icon is pressed what happens from there exactly, do I launch an activity that then launches the service from onCreate()? Or does the clicking the app go straight to starting the service?
Timothy
Refined my answer to be more useful.
Desiderio