I have an Android app that uses the LocationListener to determine the speed the car is going. Currently I show the speed by updating a TextView to show when the speed changes. I am now trying to use images of digital looking numbers to show the speed to make it look more like the dash of a car. I show 3 different ImageViews next to each other and when the speed changes I change the image to the correct number using the setImageResource like this:
speedImg.setImageResource(R.drawable.dig_1);
When I try the app it works fine for a few minutes but then eventually the phone becomes non-responsive and none of the phone buttons work and eventually Android gives me the option to force close. I can only test it in the car so I am not able to debug.
Is there another way I should be changing the image to make it more efficient? I have also thought about reducing how often the listener gets called but didn't know how many meters to set it to still get an accurate speed of the car.
Most probably you're doing some long-running operation in main UI thread. You could give StrictMode a try to detect such things.
Related
I am developing an android app which calculates screen to face distance which has one camera preview in which app detect the eyes and calculates the distance and show distance above the preview and adjust the android system font according to distance calculated.
Currently the app calculates distance when i run it.
I want this app to continuously calculate the distance in background and change the font accordingly but now its not calculating distance in background.
I expect that app should not pause in background and calculate the distance even in background and change the system font accordingly.
You can use WorkManager. WorkManager is best for background jobs. Refer following links
https://developer.android.com/topic/libraries/architecture/workmanager (Introduction)
https://github.com/googlesamples/android-architecture-components/tree/master/WorkManagerSample (Examaple)
This sounds like a typical example of a task you want to do in a background Service. To quote the description from the Android documentation:
A Service is an application component representing either an application's desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use.
Use AsyncTask and you can achieve this by using its core methods like doInBackground and progressUpdate()
Just like what #FreddaP said, for me, I would use a Service in here because it seems like it only needs to go a single task, which is calculating the distance of the phone from a face, over and over again.
If you want to be a bit adventurous, use native code to increase it's speed (not like I know how to make it work though).
This SO answer seems to be what you'll need. Sorry I haven't used the camera before in my apps.
I think that this particular problem (to use the camera without preview) has already been addressed in this post
I have been working on a game where speed is required to score well, in the game the user is clicking on objects and using them with other objects which are held in a gridView that's being controlled by an imageAdapter. I have noticed that when I click quite fast some clicks don't register, I have cleaned up the code running when the user clicks but that doesn't seem to be the problem since I tested it just highlighting objects and not running code when clicked and it was just as slow. So is there a way to speed up the click detection, or would this be limited by the speed of the device its self, I have been testing on an htc one m8.
Return as soon as possible from the handler and run the UI update code in background with 'runOnUiThread()'.
Notice that changing view status MUST be done in the UI thread or the Android runtime will throw an exception. You can work complex calculations in background 'AsyncTask' and call 'runOnUiThread()' from within them whenever you want to update UI components.
As far as I know, there is no way to do such think. It depends on the speed of your hardware. But what you can do is to use the onTouch listener. In this way you listen only after one action(when it is pressed). for onClick it is registered 2 actions(when u press the button and when u release the button). In this way maybe you could do it faster.
You can also try this:
http://developer.android.com/guide/topics/graphics/hardware-accel.html
I am working on an Android app, which warns the user if he has not been moving for a fixed period of time.
I wanted to determine if the user moves by comparing the GPS positions every few seconds.
Since I have however heard that the GPS positions are very inaccurate and can vary greatly, I was wondering what the best way would be to determine if the user does not move?
I would think using the accelerometer would be a fairly good way of determining if they had been moving.
I would look at using activity recognition. You can get more information about it here:
http://developer.android.com/training/location/activity-recognition.html
Well i have successfully obtained the light value, however, it is EXTREMELY delayed. Approx 3~5 seconds even when using .SENSOR_DELAYED_FASTEST also even when entering 0 as the rate. Its so slow. I have the program check light sensor values upon screen on then change brightness accordingly HOPING it would solve the horrible automatic brightness delay. but after messing around with it, it seems to me that this is simply a flaw in android. It simply cannot update fast enough. I have used getDefaultSensor() but according to android documention this value can be delayed/filtered, but upon reading another post on stackoverflow the getSensorList() and getDefaultSensor() return the same values and that getSensorList() is no different than getDefaultSensor()
The reason for my question is: Is this correct? Is android simply a fail at updating immediatly? its funny cause my Windows MOBILE(not phone) can update immediatly and i loved it. but with all android devices ive seen its the same thing. so is this just a flaw in androids programming? Is there a way for me as an app dev to fix this? or do we have to live with it?
As I know you cannot get it faster. Please take a look on this question and answer: https://stackoverflow.com/a/5060690/1381641
I don't have the solution for your problem, but I do have an explanation for it. The Ambient light sensor has a delay because of the integration time downloads Sensor Box for android from the Playstore.
You will get the hardware ID of your ambient light sensor, then google search it, and you will get a PDF with technical details about that specific model number. Every Android or IOS phone does NOT use the same hardware.
In that PDF, you will get an integration time. It exists to keep the brightness control stable and delayed as well as sensible. If it is low, and you are in a disco your brightness level will keep on flickering. The same for outside, sometimes some shadows make it go up and down if the integration time is low. It will flicker more and will not be stable.
This will also cause harm to the backlight, so instead of taking single values they compile down the values of a big time interval. My integration time was 400ms. This value is sent to the processor, and then the decision is taken.
You could change this value. It is easy, AMD hard boh depends on your expertise like to update this you have to program the ALS unit by opening the phone, connecting a programmer to it, and connecting the pins in the right way. Then sending an 8 bit signal as mentioned in the PDF (if model is programmable).
I created an app for android. I'm using canvas and making more and more "Sprites" from my Sprite class. when i start the app and there is only one sprite the game runs super fast. I made the class to create more sprites every time the timer i set up gets to 25 (so there would be an even space between each sprite). but when each of the sprites appear and it get to the max that i have made (5) it gets slower. So, my question is, How can set a custom framerate/speed to my app. Is it even possible? and if it does can you please write the easiest way? Thanks!
Here's a good article on how to set up a game loop. That will help you control the framerate of your app (make it consistent). Also, note how you doesn't wait a constant amount after drawing. Instead, you wait a constant amount of time between frames.