Set a timer for the visibility of a button - java

This is purely theoretical put let's say once I put a timer for a button to appear only 84600 second later (like 24h), will it the count down continue after the app is shut down ?
Can the user close the app and then come back the next day and find the button after the countdown is done ?
Or is there a better way to make it happen ? Like to allow the user to see it only after 24h ?

you can use ScheduledExecutorService to create such a timer. Then on every tick, you can open the app if you want, and show the button, or just show the button if the user open the app.
documentation is available here.

Related

New Activity everyday by clicking a Button

I want to make that when user clicks the Start Button, the app shows ActivityFirst (on the first day when he downloaded app), the second day when s/he taps Start - ActivitySecond will be shown etc. When the app will not have any other Activity, I want to show a popup that will say that more Activities will be added in the future.
I can do popups, Activities, Buttons, onClicks etc.
But I can't do that everyday will there be a new Activity.
Can you help me, guys?
My idea:
The user downloads the app,
The user runs the app for the first time and clicks the Start Button (here comes the ActivityFirst)
The user can look at this Activity for one day
The user runs the app on the second day and taps the Start Button (here comes the ActivitySecond)
And so on.
I hope you understand my idea, it's a very annoying problem to me.
What I would do, is save the timestamp of the first launch of the app.
Then, every time the user opens the activity, I would check how many days it's been since that timestamp, and populate the Activity accordingly.
All you need is one "DailyActivity", really.

Run program in background after the click of a button

I want to make my program run in the background after you click a button.
I'm creating a rickroll (in 2015 yeh) and when you click a button I want to play the song never gonna give you up from rick astley and get the frame closed and run in a process, so the song still continues. I already got the part of clicking the button and starting the song, but how can I make it continue in a process?
I do not think that "continue in a process" is what you want.
Just close your frame, allow your main message loop to end, and before returning from your main() function block waiting for the sound to end. Or, if you don't know how to block waiting for the sound to end, then calculate how many milliseconds long your sound is, and just Thread.sleep() for that many milliseconds.

Android: how to stop listener when app closes

When my app starts I start a location listener, I'd like to turn it off when the user exits the app, whether by pressing the back button or just putting it in the background, and I would like to resume listening when the app is back.
I couldn't find onPause/onResume for the app level, so I thought about holding a counter that will count the number of active activities and if it's 0 it will shut down the listener, but there must be a better way...
Please advise.
To detect if your app is running in background you can read this article:
http://www.vardhan-ds.co.in/2013/05/android-solution-to-detect-when-android.html
And to shut down your listener, you just need to remove the Listener from your manager.
If you need some help with this I can post some code, but I think this description will help you.

Random RSS Data

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?

How to make a protection of many times pressing the button?

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.

Categories