-1

My problem is make a function to set up themes in my application every 00:00 AM if there are new themes. As I know, to do this problem we must use a loop.

Here is my code:

private void updateThemes() {
    Thread time = new Thread() {
        public void run() {
            int time = 0;
            while(time > 86400000) {
                //invoke method or start new activity
            }
        }
    };
}

Please help me - Thanks.

Jon Egerton
  • 40,401
  • 11
  • 97
  • 129
Reza Rachman
  • 143
  • 3
  • 15
  • 2
    i think that you should learn android basics first(your application will not run forever, you should do this(i mean empty loop) coz of battery drain, a lot of other stuff) ... but you can try use this class: http://developer.android.com/reference/android/app/AlarmManager.html – Selvin Jan 09 '12 at 15:06

1 Answers1

2

Running a thread and waiting for a full day is not going to work. What if the phone is shutdown? What if the user switches to another app and your app is closed by Android because it needed the resources? Besides, it's not very battery friendly either.

You'd better use the Android AlarmManager to set the times at which you would like to check for updates. Also specify a BroadcastReceiver in your app that will receive and process the alarms. There's an example application that does this here or check this post for more info.

Community
  • 1
  • 1
THelper
  • 15,333
  • 6
  • 64
  • 104