Get Location updates in background without running Service in Android - android

I want to fetch the current Location of the user in background. I know how it can be done using Service in Android. But I would like to know is there any possibilities to get user Location without running service. Like using BroadcastReceiver or anything? I'm just trying to avoid running Service to fetch Location.
For Example I referred this link. But I couldn't follow how to do like this.
Any help will be appreciated. Correct me in case I'm asking anything wrong.
EDIT: Oh, I think in the above link he is using Service to get the Location. So I think it's not possible to get location in background without running a Service. Still suggestions are welcomed.

You Should Implement a BroadcastReceiver that receives alarm every 2 hours. That alarm is Set by Your Activity.
When the alarm is triggered by your System, Broadcast Receiver receives it, Executes Your Process in BroadCastReceiver.
This is what i can think of.

Related

Unable to start Service after App startup

Hello all i want location updates when my app is triggered first and after even it is killed i want my service to run i tried broadcast receiver for this purpose but it run on phone reboot Can anybody guide me to the right direction? Thanks
depending on the layout of your code, I believe it might be as easy as making the app perform the location update request on onResume while leaving onPause blank to test if it works for what you want. At least if I understood you correctly, that's what worked for me but it might drain your battery if you are using some power demanding location provider like GPS. And about your service to survive reboot I'm not really acquainted on that topic but from a quick read, indeed using broadcast receiver and listening for BOOT_COMPLETED to set off an intent.setAction declared after onCreate on your MainActivity should do it, but haven't tested that myself yet. Anyhow, it would be best if you can post the code you're working with so that others can see exactly what you have so far and be more helpful.
Hope it helps

What should be used for continuos background work in android app? service or intent service

In my application, I would like to send user location to server continuously for every 5 minuets,.. I don't know much about services.. I would appreciate if someone can help me.. Please give me some references to create service and intentservice examples. Thanks
You should use a Service for that. Use START_STICKY to ensure it doesn't get killed permanently and/or set an Interval starting the Service using AlarmManager.
However you probably should reconsider doing this at all. No one wants an app which uses RAM and network bandwidth all the time and leaks personal data.

Do I need service to do something when app is in background?

I have to write an app that is supposed to send user location to server.
I have class that is listening events from Android and it sends data to server bia webservice.
Do I have to put that in some service, or I can just put it into my MainActivity class code?
Im asking, because Android is still weird for me. It pauses activities and I don't know if this will work "from the background" or not.
Of course I want to update location when application is in foreground and background too.
Yes you will have to use a Service to send data in the background as well as foreground.
You can use android Service or Background Service,
based on your requirements I would suggest using the Background Service.
Here are the links for both:
Service:
http://developer.android.com/guide/components/services.html
Background Service:
https://developer.android.com/training/run-background-service/create-service.html
if you want the location irrespective of the fact that the application is open or not then you need to have a service which will keep on posting your location to the server.
Here's how you can do it ...
Read this answer
Note :
Activities can't do what you want to achieve as they exist till the user exits them (by pressing the back button, killing them or clearing the stack[Need not think of it for now if a newbie]).
There is a good article on android.com website
https://developer.android.com/training/location/receive-location-updates.html

What use to make reminder app?

I want to write reminder. What i need to use? Make service app or just standart app runing in background or another way?
Thanks for replys!
What I really liked about this question is you asked about the idea for the app that you want to implement. You didn't ask for code.
I would suggest that you should make an app which should have a broadcast receiver, but still it should have service that runs in background.
The service will check the current time with your reminder time. A broadcast receiver is required to listen to startup broadcast, because you need to start your app as soon as your handset starts.
Have a look at this.
Have a look at the AlarmManager. It allows you to schedule your application to be run at some point in the future.

Updating weather info, should I use alarm and/or a service?

I am having some design techniques about How shall I schedule a code to retrieve the weather info?
Should I use alarms to retrieve the weather each 10 minutes?
And do I need to run a service for this? Or just put the code in the Broadcastreceiver and start when the alarm fired?
This is a good question. Yes, you will need to put this code in either a service or broadcastreceiver because when and activity loses focus (meaning the user is using a different app or the phone is asleep) they pause and/or close. However, i have no experience with either Services or Broadcastrecievers, so that is as much as i can tell you.

Categories

Resources