Inconsistent Alarm Behavior

by Kevin » Thu, 29 Apr 2010 07:16:59 GMT


Sponsored Links
  have an inexact alarm that is supposed to launch a service to update
some data every hour, but it only seems to work at most 50% of the
time. I thought I did the wake lock correctly, but perhaps not.
Here's the relevant code, if anyone can give suggestions it would be
greatly appreciated.

Thanks!

TwitterAlarmReceiver.java
-------------------------------
public class TwitterAlarmReceiver extends BroadcastReceiver
{
public static final String ACTION_REFRESH_TWITTER_ALARM =
"com.molskness.stocktracker.ACTION_REFRESH_TWITTER_ALARM";

@Override
public void onReceive(Context context, Intent intent)
{
/* Create the wakelock if necessary */
if ( TwitterUpdateService.wakeLock == null )
{

PowerManager pm =
(PowerManager)context.getSystemService(Context.POWER_SERVICE);
TwitterUpdateService.wakeLock =
pm.newWakeLock( PowerManager.PARTIAL_WAKE_LOCK, "TwitterUpdateService
Wake Lock" );
TwitterUpdateService.wakeLock.setReferenceCounted( true
);
}

/* Aquire the wake lock */
TwitterUpdateService.wakeLock.acquire();

// TODO Fire alarm on next network connection after firing once
in
airplane mode.
Intent startIntent = new Intent( context,
TwitterUpdateService.class );
context.startService( startIntent );
}
}

----------------------------------------
TwitterUpdateService.java
----------------------------------------
public class TwitterUpdateService extends Service
{
public static PowerManager.WakeLock wakeLock;
public static final String TWITTERS_UPDATED = "twitters_updated";
...
...
@Override
public void onCreate()
{
Intent intentToFire;
String alarmAction;

/* Initialize the connection information objects */
connManager =
(ConnectivityManager)getSystemService( Context.CONNECTIVITY_SERVICE );
netInfo = connManager.getActiveNetworkInfo();

/* Create the recurring alarm */
alarms = (AlarmManager)getSystemService( Context.ALARM_SERVICE
);
alarmAction = TwitterAlarmReceiver.ACTION_REFRESH_TWITTER_ALARM;
intentToFire = new Intent( alarmAction );
alarmIntent = PendingIntent.getBroadcast( this, 0, intentToFire,
0 );
}

@Override
public int onStartCommand( Intent intent, int flags, int startID )
{
SharedPreferences prefs;
int alarmType, frequency;
long timeToRefresh;

prefs = PreferenceManager.getDefaultSharedPreferences( this );
/* Default update period is once a day */
frequency =
Integer.parseInt( prefs.getString( "twitter_update_interval",
"60" ) );

/* Wakeup when this alarm fires */
alarmType = AlarmManager.ELAPSED_REALTIME_WAKEUP;
/* User selected interval in minutes converted to milliseconds
*/
timeToRefresh = SystemClock.elapsedRealtime() + frequency * 60 *
1000;
/* Inexact is ok */
alarms.setInexactRepeating( alarmType, timeToRefresh,



Other Threads

1. WindowManagerService Animation problem

Hi guys, i tried to change the "task_open_enter.xml". This file
describe the animation used to open a new activity.

the original:
<set xmlns:android="http://schemas.android.com/apk/res/android"
        android:interpolator="@anim/decelerate_interpolator">
        <translate android:fromXDelta="33%" android:toXDelta="0"
        android:duration="@android:integer/config_mediumAnimTime"/>
</set>

I change to:
<set xmlns:android="http://schemas.android.com/apk/res/android"
        android:interpolator="@anim/decelerate_interpolator">
        <rotate android:fromDegrees="0.0" android:toDegrees="180.0"
android:pivotX="50%" android:pivotY="50%"
        android:duration="1000"/>
</set>

after that, when opening a new activity, the animation just goes
really strange, it doesn't rotate on center of the screen

If i want to make the screen animate 180 degress with pivot position
on a center of the screen, are there any better idea ?

Please help ....

thanks

--~--~---------~--~----~------------~-------~--~----~

2. How to Obtain Endless Views

I am developing an application in which a user keeps on scrolling and
each view displays a single text. The views are not suppose to end.
How can i achieve that?

Hope my question is clear.Waiting for the reply
--~--~---------~--~----~------------~-------~--~----~

3. Service running or not ?

4. Sense UI for 32A

5. Student Education Loan

6. ListView vs. ListActivity different default behavior

7. Where have all the Google employees gone?