• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Java code help needed -- this should be simpe

phpCoder

Lurker
I am in the process of building my first Android application. The application will poll a server every minute and request a specific web resource and process the information. All the above is working, except I can not figure out how to set a wait() 60 seconds and call the class again. As you can probably guess I am a PHP developer, it has been years since I have needed to use Java.

Any help would be great


program overview:

public class pollserver extends Activity {

public void onCreate() {
/*
- Using httpGet() to get server status
- Processing data received from server
*/
// I need to call the pollserver every 60 seconds
// just can't figure out how. I really thought this
// would have been the easiest aspect of this project

}

private void pollserver () {

}

Any suggestions for adding a wait() and call to pollserver() would be
much appreciated.


}

Coding for HTC HD2 running Android 2.2
 
import com.buzzbox.mob.android.scheduler.SchedulerManager;
import com.buzzbox.mob.android.scheduler.Task;


the following code is in the oncreate of pollserver
Not sure why this isn't working.

SchedulerManager.getInstance().saveTask(this,
"0 */5 * * *", // a cron string
(Class<? extends Task>) pollserver.class );
SchedulerManager.getInstance().restart(this, pollserver.class );
 
There are a bunch of ways each with pros and cons.

- Java has a Timer class.

- You could also use Android built in Handler class that can run a runnable with the postDelayed(Runnable r) method. (I find this easiest personally).

- You could also use a Service or Thread to handle the work in the background.

- Definitely stay away from wait(); This is a dangerous method and really shouldnt even be in java. (IMHO)

- Finally, you might want to consider using C2DM instead of polling a server (this would save your users a lot of battery)

hth
 
Back
Top Bottom