Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development

Application Development Dev Lounge for the Coder Folks



Reply
 
LinkBack Thread Tools
Old January 27th, 2012, 06:07 PM   #1 (permalink)
New Member
 
Join Date: Jan 2012
Location: Virginia Beach
Posts: 3
 
Device(s): HTC Sensation S-off'd HTC HD2 running Android 2.2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Java code help needed -- this should be simpe

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

phpCoder is offline  
Reply With Quote
Sponsors
Old January 27th, 2012, 08:38 PM   #2 (permalink)
New Member
 
Join Date: Jan 2012
Location: Virginia Beach
Posts: 3
 
Device(s): HTC Sensation S-off'd HTC HD2 running Android 2.2
Thanks: 0
Thanked 0 Times in 0 Posts
Default buzzBox

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 );
phpCoder is offline  
Reply With Quote
Old February 1st, 2012, 09:31 PM   #3 (permalink)
Over Macho Grande?
 
alostpacket's Avatar
 
Join Date: Nov 2009
Location: NY
Posts: 7,090
 
Device(s): GalaxyNexus(LTE), NexusOne, OG Droid, GalaxyTab 10.1(LTE), Eris, Logitech Revue (fishtank)
Thanks: 4,164
Thanked 3,126 Times in 1,292 Posts
Default

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
alostpacket is offline  
Reply With Quote
Old February 2nd, 2012, 03:03 PM   #4 (permalink)
Senior Member
 
Join Date: Jul 2010
Posts: 977
 
Device(s): Samsung Galaxy S II, HTC Evo 4G, Amazon Kindle Fire
Thanks: 52
Thanked 199 Times in 144 Posts
Default

The easiest way would be to use a Timer and a subclass of TimerTask as mentioned above.
jonbonazza is online now  
Reply With Quote
Reply

Bookmarks

Tags
wait() sleep()


Go Back   Android Forums > Android Development > Application Development User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 12:10 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo