mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-18 22:26:30 +01:00
add static methods for starting timer.
This commit is contained in:
parent
ed95d2e794
commit
ae6edf4ace
1 changed files with 30 additions and 0 deletions
|
@ -23,6 +23,11 @@ package org.eehouse.android.xw4;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.app.AlarmManager;
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
|
||||||
|
import org.eehouse.android.xw4.jni.CommonPrefs;
|
||||||
|
|
||||||
public class RelayActivity extends Activity {
|
public class RelayActivity extends Activity {
|
||||||
@Override
|
@Override
|
||||||
|
@ -35,4 +40,29 @@ public class RelayActivity extends Activity {
|
||||||
|
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void RestartTimer( Context context )
|
||||||
|
{
|
||||||
|
RestartTimer( context,
|
||||||
|
1000 * CommonPrefs.getProxyInterval( context ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RestartTimer( Context context, long interval_millis )
|
||||||
|
{
|
||||||
|
AlarmManager am =
|
||||||
|
(AlarmManager)context.getSystemService( Context.ALARM_SERVICE );
|
||||||
|
PendingIntent intent =
|
||||||
|
PendingIntent.getActivity( context, 0,
|
||||||
|
new Intent(context,
|
||||||
|
RelayActivity.class), 0);
|
||||||
|
|
||||||
|
if ( interval_millis > 0 ) {
|
||||||
|
Utils.logf( "setting alarm for %d millis", interval_millis );
|
||||||
|
am.setInexactRepeating( AlarmManager.ELAPSED_REALTIME_WAKEUP,
|
||||||
|
0, // first firing
|
||||||
|
interval_millis, intent );
|
||||||
|
} else {
|
||||||
|
am.cancel( intent );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue