Android program to: Display random image for 90 seconds then switch - android

I'm new to android. I need to make a program that is very basic. It needs to display a random image from my drawing folder. I can do that part because frank n stein posted How To Display Random images on image view
But I need it to stay on the screen for 90 seconds (and count down) or until a user clicks a button. Can someone help? I would really appreciate it. If you post an answer please assume I know absolutely nothing...barely the basics. But I'm trying to learn. :)

You can use a for loop with Thread.sleep() or a CountDownTimer or AlarmManager or a Handler with postDelayed option.

You can use android alarm manager with broadcast receiver,you will set alarm +90 second to this time and receiver the alarm or you must to use timer.But timer is spending battery more than alarm manager.
You can follow this tutorial for alarm manager and i think you must follow :)
http://karanbalkar.com/2013/07/tutorial-41-using-alarmmanager-and-broadcastreceiver-in-android/

Related

Change the length of the Android Alarm

The android alarm duration is basically at 1min (I think).
I would like to change it, so I can set the length/the duration at 4min for exemple (the duration of a song).
Can you tell me which methods I can call to change it ?
Can you guide me please ?
Thank you in advance !
I think you can use AlarmManager for this. http://developer.android.com/reference/android/app/AlarmManager.html
It has setRepeating method where you can set the interval you want (the second parameter is time in milliseconds that the alarm should first go off).

Change brightness on specified hours - twice a day

I have an array of specified hours for each day, when brightness should by changed for application which is awake 24/7. It happens twice a day.
What I want to achieve is to find the most economical way of implementation that problem.
Should I use AlarmManager or maybe there is a better sollution?
Activity is always awake...
If your app doesn't show any UI while it's awake, use the AlarmManager.
Finally, I decided to use an AlarmManager with BroadcastReceiver setting value in SharedPreferences and then in Activity I have a Handler which checks that value.

How can I change my existing Thread.sleep() to alarm manager

Right now I use thread.sleep(3000) and print the data in log for every 3 seconds but now I want to change it to 15 minutes.
WHats the best to use?
Is it alarm manager or handler ?
What's wrong with:
thread.sleep(1000*60*15)

How to Triggering code in background in android?

I want to trigger specific code snippet at everyday 10.00AM while app will minimized pls help me?
You need to use Alarm Manager Class.
You can find suitable example HERE.
The easiest way to achieve this is setting up an AlarmManager that will fire your intent at the time you set it to.Inside your intent you can do whatever code you want.Else setting up a background service could be a good alternative,even tough takes a little more coding

Trigger a notification every x days

I want to trigger a notification in the status bar every x days(that the user will define in the application). How can i code this ?
Thank you.
AlarmManager was designed for stuff like that.
Assuming you already know how to code an android app, you can see these pages for code examples:
To trigger a notification in the status bar: http://developer.android.com/guide/topics/ui/notifiers/notifications.html
To run the trigger evey x days, you can use AlarmManager: http://developer.android.com/reference/android/app/AlarmManager.html

Categories

Resources