I was curious and could use a bit of help with a Timer app I'm working on for Android. Is it a good idea to just use one single TextView that displays the time, or would it be better to use three individual TextViews (one for hours, minutes, and seconds)? I'll be using a Number Picker Dialog to set the values, but I am a bit confused how that will work if I just use one TextView.
Thanks for any repsonses.
Also, I can't use Timer, Chronometer, CountdownTimer, or Digital Clock View for this timer. Restricted to Asynch Tasks, Handlers, Threads. Professors orders.
Use Chronometer class of android API. It has methods for start and stop Chronometer. The XML View also available. also you will be able to pause and resume the Chronometer.
Three fields available (H:MM:SS) for timer in Chronometer.
Related
I have a splash screen that waits 2 seconds and invokes the main activity which is a dashboard that retrieves and calculates a lot of data from a database.
The issue is that a long lasting black-screen is displayed between the 2 activities (after the 2 seconds of the splash screen), and the user should wait for the 2nd activity to be displayed, because the activity is doing a lot of stuff before showing up.
Is there a straightforward solution to avoid the hard work on the onCreate method.
You can launch a ProgressBar while the database activity is going on, since database stuff is designed to run in background thread, it is a good practice to introduce a kind of interactivity such as indeterminate ProgressBar etc so that the user will understand some sort of operation is being performed before interacting with the UI.
Another way to look into it is to ensure you are not running threads that should run in the background on the UI thread because this will lock the UI and this is not a good practice.....
for my project I need to build an own, custom DatePicker. I can't just use the standard DatePicker, because I need features like selecting multiple dates, disabling special dates, etc.
I planned to build my own custom DatePicker as close to the standard DatePicker as possible.
Therefore I have decided to use a ViewPager in which I nest a custom View that holds a custom ViewHolder containing just a TextView to Display the current Month and a RecyclerView to Display the Actual Days of the month in question.
The result looks something like that:
I don't think it is necessary to provide the whole code (adapters, layouts etc.) because the whole thing is fairly straight forward but if you need to see, I can add it after the fact.
Now to my problem: When I start the activity, the whole application stops for about 3 seconds, and I get the following logcat-output:
I/Choreographer: Skipped 111 frames! The application may be doing too much work on its main thread.
I narrowed the problem down to the RecyclerViews.
(when they are deactivated, there is no freezing/stuttering whatsoever)
When the activity starts, the application has to load 3 full Recyclerviews (because I set viewPager.setOffscreenPageLimit(2); )
and that initial loading causes the whole application to freeze for a short amount of time. After everything is loaded, the whole thing works completely lag-free.
To this problem I have 2 different solutions in mind:
Load the RecyclerViews in another Thread
The idea is, that the activity starts, and the RecyclerViews are only shown, when they are loaded. This wouldn't be perfect, but at least the activity would start without causing the whole application to freeze.
Substitute the RecyclerViews with something better performing.
Is there even a View/Structure that a) enables me to display a gridlike Structure and b) is better performing than a recyclerview?
Initially I chose the RecyclerView for displaying the days, because I thought that the Standard DatePicker uses it too, but after some digging in the integrated classes I am no longer so sure about this.
To me it seemed like the days are drawn without any View whatsoever. (I could be wrong about that)
Is there any possiblity, that one of those ideas could be working?
And if not, is there another way to fix the performance-issue?
Thanks in advance
I'm kind of new to android so please bear with me.
I need help with something, I have a rss feed that has energy tips in it. Instead of displaying all of them inside a listview I would like to display them one at a time on an activity that has a timer that automatically switches them inside a textview this activity would also have two buttons "prev" and "next" which would override the timer. Is it possible? Any pointers would be appreciated.
Thanks,
It sounds like the kind of view you might be looking for is a ViewSwitcher. This will allow you to switch and animate between different views in your app. While you can imagine more elaborate configurations (really, anything), this might be a good choice to you that's already baked into the framework. How to control the view is a slightly different question, however, there are multiple ViewSwitcher tutorials out there, and you can easily implement a Timer which switches between the views. What you do is fairly simple: tell the timer to fire after some interval. If the user presses some button before the timer fires, cancel the timer and (perhaps) reset it?
I've been working on a drum machine app, and the latency between the time you press the button and the time the sound plays is unbearable. I have seen some people use multitouch and gridviews, and make several buttons able to be pressed at the same time, but I honestly have no knowledge of those. How could I set up multitouch or gridviews to reduce the latency?
I would guess the multitouchable buttons are a very custom implementation. You won't ever be able to touch two ordinary buttons simultaneosly, since they are made for single touch and are based on focus gain etc.
Here's my idea behind a multitouchable implementation:
You create a very custom view which will draw all buttons you need. This view should override onTouchEvent and react on multitouch. I never tried that, but this is the only option I can think of.
In my app I use a camera, and I want to take a pictures. In my app is button (Photo). If I press it one times - all work perfect, but if I press button many times until camera take picture, my app hangs. How can I fix it?
In your onClickListener call Button.setEnabled() and set it to false.
Then set it to true when you've finished taking the photo.
Use a listener that disables the button on press (setEnalbed(false)), than start a countdown thread that re-enables it after some time, 200ms maybe, or whatever fits the best.
After second thoughts this might not be a really good idea.
There is a chance that the thread will not be scheduled to run, so if you exactly know the point when you can re-enable the button in your code, don't use threads.