I'm working on an app which will trigger a future event. I set the AlarmManager to achieve this. The code is general:
Intent alarmIntent = new Intent(this, MyService.class);
PendingIntent pintent = PendingIntent.getService(this, 0, alarmIntent, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager alarm = (AlarmManager)getSystemService(ALARM_SERVICE);
alarm.set(AlarmManager.RTC_WAKEUP, time, pintent);
I would like to see how I can set multiple future events to the AlarmManager. The times for future events are all independent, some may repetitive and some may one shot.
Any body has experience on this feature? Would you mind sharing here.
You need to make sure that the PendingIntent that you pass to the AlarmManager is unique for each event. To make the PendingIntent unique you have some alternatives:
Use a unique requestCode argument in the call to PendingIntent.getService()
Use a unique ACTION in the Intent that you pass to PendingIntent.getService()
Use unique DATA in the Intent that you pass to PendingIntent.getService()
Note: Using different EXTRAS in the Intent that you pass to PendingIntent.getService() will not make the PendingIntent unique!
Thanks David.
I achieved that by using a unique requestCode.
Related
I register a timeout with:
timeout_tag = g_timeout_add(250, update_time, NULL);
and destroys it with
g_source_remove(timeout_tag);
But as I open multiple instances of the same app, the timeout triggers update_time in all instances instead of just one. How would I isolate them?
I'm creating a new application with
app = gtk_application_new("com.lunacd.reminder", G_APPLICATION_FLAGS_NONE);
Should I generate a uuid and append it to com.lunacd.reminder so that the identifier remains distinct?
As #jcoppens pointed out, timeouts are triggered independently. This question is invalid.
I'm acting as an acceptor. Is there a way to set sequence numbers manually?
The first idea I had, was to modify .seqnums files, but it does not work.
Google mentions existence of setNextSenderMsgSeqNum and setNextTargetMsgSeqNum methods, however I can't tell on which object I should call them (using quickfixj 1.4).
I'm aware that setting sequence numbers by hand is discouraged and there are bunch of flags like ResetOnLogon and ResetOnDisconnect, but I have no control over initiator and there are bunch of other acceptors (test-tools) which are using the same session.
Application myApp = new FIXSender();
settings = new SessionSettings(sessionConfig);
MessageFactory messageFactory = new MessageFactory();
MessageStoreFactory storeFactory = new FileStoreFactory(settings);
LogFactory logFactory = new FileLogFactory(settings);
Acceptor acceptor = new SocketAcceptor(myApp, storeFactory, settings, logFactory, messageFactory);
acceptor.start();
First of all you need to explore the quickfixJ code to see how it is done.
Secondly what is the reason to use such an old version of quickfixJ ? Why not upgrade to the most recent version.
Thirdly you should be very wary of changing sequence numbers if you don't understand properly how they are used in the communication. If you don't understand you are guaranteed to get into murky problems.
You can do something like
Session.lookupSession(sessionID).setNextSenderMsgSeqNum())
But before you do it, it is very important to understand how sequence numbers are used
You can set the FIX fields, override the toAdmin callback
#Override
public void toAdmin(Message message, SessionID sessionId) {
message.setBoolean(ResetSeqNumFlag.FIELD, true);
}
I have created an observable by using Observable.FromEventPattern. Let's call it fromEvents.
I want to create another observable that wraps fromEvents. We'll call this 2nd observable wrapper.
When wrapper is subscribed to it should:
Publish the most recent item from fromEvents if any.
Publish the rest of items coming from fromEvents
Obviously wrapper will need to maintain a subscription to fromEvents so that it always has access to the most recent event.
I have tried various combinations of Replay, Publish, PublishLast, Observable.Defer and I'm never quite getting the results I'm looking for.
I'm certain Rx has operators that will meet my needs, I'm just unsure of exactly how to put everything together, being the newb that I am.
I think I've been able to get what I want by doing this:
Events = Observable.FromEventPattern(...).Replay(1).RefCount();
// contrived example
// in my real app the subscription lives for a specific duration
// and Events is exposed as a readonly property
using(Events.Subscribe())
{
// get most recent or wait for first
var e = Events.FirstAsync().Wait();
}
Example using the Publish overload that uses a BehaviorSubject behind the scenes to keep track of the most recent event.
var fromEvents = Observable.FromEventPattern(...);
var published = fromEvents.Publish(null);
// subscribe to this one
var wrapper = published.Where(e => e != null);
// start collecting values
var subscription = published.Connect();
wrapper.Subscribe(...);
Regarding the BoilerplateJs example, how should we adjust those modules to be intercommunicate in such a way once the user done any change to one module, the other related modules should be updated with that change done.
For example, if there is a module to retrieve inputs from user as name and sales and another module to update those retrieved data in a table or a graph, can you explain with some example ,how those inter connection occurs considering event handling?
Thanks!!
In BoilerplateJS, each of your module will have it's own moduleContext object. This module context object contains two methods 'listen' and 'notify'. Have a look at the context class at '/src/core/context.js' for more details.
The component that need to 'listen' to the event, should register for the event by specifying the name of the event and callback handler. Component that raise the event should use 'notify' method to let others know something interesting happened (optionally passing a parameter).
Get an update of the latest BoilerplateJS code from GitHub. I just committed changes with making clickCounter a composite component where 'clickme component' raising an event and 'lottery component' listening to the event to respond.
Code for notifying the Event:
moduleContext.notify('LOTTERY_ACTIVITY', this.numberOfClicks());
Code for listening to the Event:
moduleContext.listen("LOTTERY_ACTIVITY", function(activityNumber) {
var randomNum = Math.floor(Math.random() * 3) + 1;
self.hasWon(randomNum === activityNumber);
});
I would look at using a Publish-Subscribe library, such as Amplify. Using this technique it is easy for one module to act as a publisher of events and others to register as subscribers, listening and responding to these events in a highly decoupled manner.
As you are already using Knockout you might be interested in first trying Ryan Niemeyer's knockout-postbox plugin first. More background on this library is available here including a demo fiddle. You can always switch to Amplify later if you require.
Ok... so i guess the title is a bit confusing. so i will explain:
I have an NFC app which i handle a NDEF_DISCOVERED succesfuly in activity A. then a new activity is launched (B).
In this new activity (B) i want to be able to catch another tag and let activity A handle it as before, so i use OnNewIntent to get this intent of the tag and want to start activity A.
But if i call startActivity(myIntent) with the traditional myIntent = new Intent(this, A.class) then activity A launced with this myIntent and i want the activity A to handle the tag intent that was 'caught' on activity B..
how can i do that?
Thanks.
You should be able to add your tag intent in activity B as an extra to the traditional intent with myintent.addExtra("tagkey", tagIntent). Because Intent implements Parcelable, it will be added as a Parcelable extra. Then in the onCreate() of activity A, put something like:
Intent intent = getIntent();
if (intent.hasExtra("tagkey")) {
setIntent(intent.getParcelableExtra("tagkey")
}
Replace the string "tagkey" with whatever is most relevant to your own code. You can put a similar snippet in onNewIntent() as well.
If the NDEF message type is specific enough such that only your Activity A will match it, you can set 'android:launchMode="singleTask"' in the activity section of your Android manifest for this Activity. Activity B will then be closed whenever you scan a new tag with the same type of NDEF message.