This quick start tutorial shows you how to integrate a background task in your Android application using BuzzBox SDK and how to integrate BuzzBox Analytics
Download our sdk from here and copy it in you project lib folder
Include it in your project build path: in Eclipse: Menu > Project > Build Path > Add Jar
Other resources for this example:
Add the following permissions in your manifest.xml
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Add the following Activities and Services
<activity android:name="com.buzzbox.mob.android.scheduler.ui.SchedulerPreferenceActivity" /> <activity android:name="com.buzzbox.mob.android.scheduler.ui.SchedulerLogActivity" /> <activity android:name="com.buzzbox.mob.android.scheduler.ui.NotificationHistoryActivity" />
<receiver android:name="com.buzzbox.mob.android.scheduler.SchedulerReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED"/> <action android:name="android.intent.action.TIME_SET"/> <action android:name="android.intent.action.DATE_CHANGED"/> <action android:name="android.intent.action.TIMEZONE_CHANGED"/> </intent-filter> </receiver> <service android:name="com.buzzbox.mob.android.scheduler.ScheduledService"></service>
public class WeatherTask implements Task { @Override public String getId() { return "weather"; } @Override public String getTitle() { return "Current Weather"; } @Override public TaskResult doWork(ContextWrapper ctx) { String zip = "94103"; TaskResult res = new TaskResult(); try { HttpUtilsResponse resp = HttpUtils.http( ctx, "http://query.yahooapis.com/v1/public/yql?q= select%20item.forecast%20from%20weather.forecast%20where%20 location%3D%22"+zip+"%22&format=json", false); JSONObject forecastJson = resp.getJSONObjectResponse() .getJSONObject("query") .getJSONObject("results") .getJSONArray("channel").getJSONObject(0) .getJSONObject("item") .getJSONObject("forecast"); int code = forecastJson.getInt("code"); String text = forecastJson.getString("text"); String date = forecastJson.getString("date"); if (code<=21) { res.addMessage( new NotificationMessage(null, "Weather Forecast!", "Bad weather Alert!", date +" : "+ text, R.drawable.scheduler_notification) .setNotificationSettings(true, false, false) .setNotificationClickIntentClass( null )); // <-- your Activity here } } catch (Exception e) { Log.e("weather.task", e.getMessage(), e); } return res; } }Notes: your Task can be as simple as creating a NotificationMessage.
int openAppStatus = AnalyticsManager.onOpenApp(this); if (openAppStatus==AnalyticsManager.OPEN_APP_FIRST_TIME) { // very first time SchedulerManager.getInstance() .saveTask(this, "0 8-19 * * 1,2,3,4,5", WeatherTask.class); SchedulerManager.getInstance() .restart(this, WeatherTask.class); } else if (openAppStatus==AnalyticsManager.OPEN_APP_UPGRADE){ SchedulerManager.getInstance() .restartAll(this, 0); // they need to be rescheduled }Your Task will run every hour, from 8am to 7pm, Monday - Friday, according to the cron string 0 8-19 * * 1,2,3,4,5
@Override public boolean onOptionsItemSelected(final MenuItem item) { final int id = item.getItemId(); if (id == R.id.menu_main_scheduler) { SchedulerManager.getInstance() .startConfigurationActivity(YourActivity.this, YourTask.class); } return super.onOptionsItemSelected(item); }

The Settings Activity can be configured from the manifest.xml. An example follows:
<meta-data android:name="SchedulerPreferenceActivity.show.daysOfWeek" android:value="true" /> <meta-data android:name="SchedulerPreferenceActivity.show.frequency" android:value="false" /> <meta-data android:name="SchedulerPreferenceActivity.show.enabledFromTo" android:value="false" /> <meta-data android:name="SchedulerPreferenceActivity.show.notificationSettings" android:value="true" /> <meta-data android:name="SchedulerPreferenceActivity.show.SelectAtWhatTimes" android:value="true" />
The Settings are saved automatically when the activity is closed.