I use AlarmManager to start Service at specific time.

 intent = new Intent(ACTION_RECORDER_START);
  intent.putExtra(EXTRA_COMMAND_ID, command.id);
  pendingIntent = PendingIntent.getService(context, 0, intent, 
PendingIntent.FLAG_ONE_SHOT);
  alarmManager.set(AlarmManager.RTC_WAKEUP, command.start, pendingIntent);

But if there're multiple events scheduled, only the last one is executed. This 
happens because intents are equal and extras are not compared. 

What I tried:

1. Custom Intent class:

 static class AlarmIntent extends Intent{
        
        public AlarmIntent(String action){
                super(action);
        }
        
        @Override
        public boolean filterEquals(Intent other){
                if(super.filterEquals(other)){
                        
                        long id  = 
getExtras().getLong(AudioRecorder.EXTRA_COMMAND_ID, -1);
                        long otherId = 
other.getExtras().getLong(AudioRecorder.EXTRA_COMMAND_ID, -1);
                        if(id == otherId){
                                return true;
                        }
                }
                return false;
        }
    }

But filterEquals is never called.

2. Using setData. This should ensure that intents are not equal and not 
overriden. But my Service never starts.

 intent = new Intent(ACTION_RECORDER_START);
 intent.setData(Uri.parse("myscheme:" + command.id));
 pendingIntent = PendingIntent.getService(context, (int)command.id, intent, 
PendingIntent.FLAG_ONE_SHOT);
 alarmManager.set(AlarmManager.RTC_WAKEUP, command.start, pendingIntent);

In manifest:

 <service android:name=".MyService" >
            <intent-filter>
                

            <data android:scheme="myscheme:" />

<action android:name="com.package.START" /> <action 
android:name="com.package.STOP" /> </intent-filter> </service>


Any ideas?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to