threads or service
I need to have gps running all the time in my application, but I don´t know if it is better throw it like a thread inside of the activity or if I should creat a Service and then in the Service, throw the thread
Can anybody help me?? Thank you!!
P.D: Sorry for my English
My answer doesn´t lie in how my application will work because I want my application goes to the background and it works. I'm going to try to explain what my application consists: It has one activity that starts one service with the gps, the locations from gps are compared with others locations that it has in a file. When a condition is true, then it starts another service running a multimedia player.
So if I am watching another application or if I have the device in my pocket, I want my application continues running.
Asked by: Agata387 | Posted: 24-01-2022
Answer 1
I suppose your answer would lie in how your application will work. If you want to receive the GPS data even after your application has been pushed to the background by pressing home button or back button then you should have it in a service since the life cycle of a service is different to that of an Activity.
If the GPS data is only required within your application and you don't need it ones the application is closed then threads are a better option as Kavitesh has mentioned, threads are a much quicker and easier approach
Answered by: Lana498 | Posted: 25-02-2022Answer 2
Could you explain some more please? Because we need to know what your application is to do. When your app is always visible, you don't need a thread or a service, you should implement a listener and register that to the LocationManager.
When you application should go to the background, then you should implement a Service.
Answered by: Julian971 | Posted: 25-02-2022Answer 3
Two things which you need to consider:
- If the GPS information is required only for your application then have a thread which pools GPS information every second or interval set by you. This way your application gets the information from GPS and you dont have to complicate things by making a service. Remember, By making a thread within your application you need to start your application so that you can obtain GPS information.
- Now lets say you want GPS information for other applications also. Then using a service is a good idea. That way other applications can also obtain GPS information and use in their application. Ofcourse, this wont happen magically that all application can get the GPS information by running the service. You would have to write code and provide interfaces so that all other applications along with your application know how to interact with the service.
Now using a thread in application is quicker and neat if it meets your requirement. However, like i mentioned your application needs to start before using the GPS information.
With Service, you can even run the service at start up. So you need not start your application to start the GPS. However, unless required go for thread in the application.
Answered by: Chester793 | Posted: 25-02-2022Similar questions
android - digital compass problem
I am creating an augmented reality application and I noticed that the stored locations don't appear appear on the correct direction if I try to use the camera view (using layar or wikitude API).
The problem is that the digital compass doesn't show north correctly when you try to look at the known objects through the camera view. If align the phone with the ground (look at my shoes) the locations appear at the screen accord...
android - How to remove labels from a MapView?
I am trying to make a satellite view (via a MapView) without labels. How can I do this?
android - Custom title with image
i'm creating custom title for activity by disabling standard one and managing everything myself. I wonder if it's possible to replace/theme standart title to my needs.
I can customize size, background image, and text via themes by changing windowXYZStyle items.
The only thing i couldn't find - how i can add image instead of text.
I've tried requestWindowFeature(Window.FEATURE_CUSTOM_TITLE)
and ...
canvas - Android draw with blur
I need do draw on Android's Canvas using Blur effect,
it is a very simple feature,
I need to draw a circular area, which is blurred (the foreground) and the background transparent, I can do everything with manipulating the colour alpha to do it with custom transparency but I need it to be blurred instead of transparent..
any ideas?
layout - How to resize a android webview after adding data in it
In a layout (linear, vertical) hierarchy I've got several views and one of them is a WebView.
They all have same parameters:
android:layout_width="fill_parent"
android:layout_height="wrap_content"
For all views, the spacing between elements is correctly handled but for the Webview there is a lot of spaces after the displayed text inside.
I set the (HTML) text of the webview in the ...
How to find easily the source of an android class
I know I can access android source code from https://android.googlesource.com, but it's hard to select the right git repo if I only know the package and the name of an android class.
Isn't there a way to locate a file in https://android.googlesource.com?
camera - Android Intent Save Path
At the moment I am using two intents. One for voice-recording, another for the camera:
Intent photoIntent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(photoIntent, ACTIVITY_TAKE_PHOTO);
Intent voiceIntent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
startActivityForResult(voiceIntent, ACTIVITY_RECORD_SOUND);
My aim is to put an Extra to each of t...
Android "hover" event in custom layout
I have a custom layout that I have written that basically just displays a bunch of ImageViews. I am handing onTouch events for all the ImageViews in my layout.
However, if a user touches one imageView and then drags over another ImageView, I would like to be able to handle that as well.
How would I go about capturing this behaviour?
android - What is the ideal place to cache images?
I am fetching a lot of thumbnails in my application from a remote server and lazy-loading these in a list view.
The image fetches run in a background AsynTask and when completed the fetched images are stored in a HashMap using SoftReferences.
This works just fine but when the images in the cache gets GC’d, the fetches have to be rerun.
I could have stored them on the SD card so there would be no...
How to create a tree view in Android?
There are no controls in Android that provide Tree-like View. There is an ExpandableList View which I suspect could be used to creating one.
Have you tried imlpementing such a control?
How would one implement such a control in Android?
Still can't find your answer? Check out these communities...
Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android