06-09-2010 05:05 AM
I'll try be as concise and as accurate as possible, but this scenario seems a little esoteric to me, hence...
I have a "standard" SendListener (ala net.rim.blackberry.api.mail.SendListener) listenin
The idea behind my sendMessage implementation is to "wait" a little while (non-blocking) and then start a thread which does the body of work required.
public boolean sendMessage(net.rim.blackberry.api.mail.Message message) {
wrapThreadInTimer();
return true;
}
I wait (using a scheduled Timer), then start a thread.
private void wrapThreadInTimer() {
new Timer().schedule(new TimerTask() {
public void run() {
new Thread() {
public void run() {
//body of work performed here
}
}.start();
}
}, 1000);
}
Now this works perfectly when an email is sent from the messages application (Messages -Compose Email).
The Esoteric Bit
However, the esoteric part is when sending from the Address Book application (Address Book -(Select Contact) - Email Contact) the Timer never executes it's schedule (TimerTask).
I have also tried a variation, wrapThreadInTimer() which starts a thread immediately which in turn sets up a scheduled Timer. Essentially, swopping Timer and Thread order on the above code. Again, the TimerTask does not execute when sending from Address Book only. Otherwise works fine when sending from Messages.
A third variation (plain Thread without the TimerTask) works fine for both sending scenarios.
private void startThreadImmediately() {
new Thread() {
public void run() {
new Worker();
}
}.start();
}
It seems that when sending an email directly from the Address Book, Timers are mysteriously dropped?
Behaviour reproduced on 4.6 and 4.5 thus far.
Solved! Go to Solution.
06-09-2010 05:41 AM
Using the scenario where both sends work (startThreadImmediately() becomes delayWorker())
Thread [net_rim_bb_addressbook_app(128)id=1064738816] (Suspended .....)
private void delayWorker() {
new Thread() {
public void run() {
Thread.sleep(1000); //try..catch omitted for readability
new Worker(); //doesn't execute from addressbook_app only
}
}.start();
}
So it's not Timers (as I first thought) but a threading issue which only plays out from addressbook_app.
Anybody have an idea why?
06-10-2010 03:50 AM
ok. figured it out. not _that_ esoteric anymore.
the address book process exits/terminates once it's sent the email.
which is strange behaviour (i think?) given then process
open address book
select contact
select email address of contact
click send email
(opens email window... type in message)
click send
NOTE: address book application is now closed
i would have expected (but never really noticed until now) that the address book app would remain open so you could continue your *original* thread which was looking up contacts.
be that as it may- it's not mysterious at least