checkpoint: add service that's launched at app start and spawns a

thread that stops itself immediately.  Eventually that thread will
check the relay for pending moves, put up a notification offering to
open the game that has moves pending, and schedule itself to run again
later before stopping itself.
This commit is contained in:
Andy2 2010-08-19 07:47:11 -07:00
parent 019da83d60
commit 25e7889c28
3 changed files with 102 additions and 0 deletions

View file

@ -94,5 +94,7 @@
</intent-filter>
</activity>
<service android:name=".RelayService" />
</application>
</manifest>

View file

@ -129,6 +129,9 @@ public class GamesList extends ListActivity {
setListAdapter( m_adapter );
FirstRunDialog.show( this, false );
Intent service = new Intent(this, RelayService.class );
startService( service );
}
@Override

View file

@ -0,0 +1,97 @@
/* -*- compile-command: "cd ../../../../../; ant install"; -*- */
/*
* Copyright 2010 by Eric House (xwords@eehouse.org). All rights
* reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.eehouse.android.xw4;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
public class RelayService extends Service {
private NotificationManager m_nm;
@Override
public void onCreate()
{
super.onCreate();
Utils.logf( "RelayService::onCreate() called" );
// setupNotification();
Thread thread = new Thread(null, m_task, getClass().getName() );
thread.start();
}
@Override
public void onDestroy()
{
Utils.logf( "RelayService::onDestroy() called" );
super.onDestroy();
// m_nm.cancel( R.string.running_notification );
}
@Override
public IBinder onBind( Intent intent )
{
Utils.logf( "RelayService::onBind() called" );
return null;
}
//@Override
// protected int onStartCommand( Intent intent, int flags, int startId )
// {
// Utils.logf( "RelayService::onStartCommand() called" );
// // return super.onStartCommand( intent, flags, startId );
// return 0;
// }
private void setupNotification()
{
m_nm = (NotificationManager)getSystemService( NOTIFICATION_SERVICE );
Notification notification =
new Notification( R.drawable.icon48x48, "foo",
System.currentTimeMillis());
PendingIntent intent = PendingIntent
.getActivity( this, 0, new Intent(this, BoardActivity.class), 0);
notification.setLatestEventInfo( this, "bazz", "bar", intent );
m_nm.notify( R.string.running_notification, notification );
}
// Thread that does the actual work of pinging the relay
private Runnable m_task = new Runnable() {
public void run() {
// Set an alarm to try again in n minutes, then quit.
RelayService.this.stopSelf();
}
};
}