How Can I Display A Text Perday In My Android App
I'm building a quotes app and i want the app to display a text on the startup page of my app, but i cant seems to get it right. Here is the code i tried... public class MainActivit
Solution 1:
I don't think you need to update the quote from another thread because the user wont be looking at the startup page of your app for 24 hours. Just get a qoute according to the current date every time the start up page is created.
//Display a text on screen in every 24 hours
//seed the random with the current date to get new random number only if the date is changed.
Calendar cal = Calendar.getInstance();
int seedVal = cal.get(Calendar.YEAR)*12*30+cal.get(Calendar.MONTH)*30+cal.get(Calendar.DAY_OF_MONTH);
Random rand = new Random(seedVal);
rand.nextInt(AllQuotes.LIFE.length);
lv.setText(AllQuotes.LIFE[x]);
nam.setText(AllQuotes.NAMELIFE[x]);
Solution 2:
- If you want it to run every 24 hours, the math to convert it to milliseconds is
60000 * 60 * 24
.60000 * 24
will give you 24 minutes. - You should be using AlarmManager for such long intervals.
Post a Comment for "How Can I Display A Text Perday In My Android App"