Juppy
Juppy

Reputation: 111

First application android, relationship between activity and service

I have trouble in my first application, I would like to know how I can interact with a Service from my Activity. The app uses the accelerometer, not just measure a certain value should take a picture and call the activity to save it.

Upvotes: 0

Views: 191

Answers (3)

Sarim Javaid Khan
Sarim Javaid Khan

Reputation: 830

If you need to interact with a web service then Use HttpClient,HttpGet , HttpPost objects.

Check this link for details.
http://kasperholtze.com/android/android-getting-data-from-a-webservice/

Upvotes: 0

Rauf
Rauf

Reputation: 46

Fire an Intent from Activity Like below :

Intent intent=new Intent(this,Service.class);

startService(intent);

Upvotes: -1

MDMalik
MDMalik

Reputation: 4001

I guess you should understand more about Activity And Service

In simple words to make you understand

Activity Its like you performing some action, like talking, walking, something where User will see and operate.

Service Its like your breathing system, your blood circulation system you don't make sure your blood is circulate at an interval. It just happens.

Yes, in programming Android you have the ability to start a Service when you desire, Stop a Service. But you can't get the value back from the service like you can get in function() .

I hope I have given some idea from real world to make you understand.

Yes, in your case you could keep your service of accelerometer running. Once it reaches a particular value you can make sure that your Service takes the picture for you in the background.

Thats something you can do. I hope I have given you a satisfactory explanation.

Upvotes: 2

Related Questions