Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
New Contributor
bryanallott
Posts: 9
Registered: 10-23-2009
Accepted Solution

SendListener From Address Book Cancels Timers

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) listening on email send events. This works 100%, no issues there and the event is triggered as expected. All good.

 

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.

Please use plain text.
New Contributor
bryanallott
Posts: 9
Registered: 10-23-2009

Re: SendListener From Address Book Cancels Timers

Using the scenario where both sends work (startThreadImmediately() becomes delayWorker())

But sleep a bit before starting work, the thread doesn't re-enter but ONLY inside the context of  net_rim_bb_addressbook_app.

 

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?

 

Please use plain text.
New Contributor
bryanallott
Posts: 9
Registered: 10-23-2009

Re: SendListener From Address Book Cancels Timers

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

Please use plain text.