Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Regular Contributor
kamaleshpandey
Posts: 91
Registered: ‎11-10-2009
My Device: BB 9810
My Carrier: Generic
Accepted Solution

Status Indicator is not refreshing from Background process

[ Edited ]

Hi,

 

My Application is auto start, it shows the numbers of pending messages on HOMESCREEN with an ICON and NUMBER,

 

But it get updated properly when my application is in foreground ,

but when it goes to background,

and then some Message gets failed  then it’s not updating the current ICON+ NUMBER instead of that it create  a new ICON+ NUMBER,

 

Please Help me.

 

Here I am writing my code to set and reset...

public class IconBanner {
	
	static EncodedImage image = null;
    static ApplicationIcon appIcon = null;
    static ApplicationIndicator appIndicator = null;
    static ApplicationIndicator mAppIndicator = null;	
    static ApplicationIndicatorRegistry appIndicatorRegistry = null;
	
    
    public IconBanner() {
    	 
	}
	 
   
    
    

	    /**
	     * Method to set banner image i.e. application icon on home screen of device.
	     * to show number of Unsent Email even if application is closed.
	     */ 
	 
	 public static void setBanner() 
	    {
	    
		 
	    
		 
		 	MailScreen mailScreen = new MailScreen(Application.getApplication());
	    	FailedSendsSettings sendsSettings = new FailedSendsSettings(Application.getApplication());
	        try {
	        	int tmp_numberOfMails = mailScreen.getNumberOfPendingMails ();// calclate no of pending message
	        	
	        	 System.out.println("Enter in  setBanner " +tmp_numberOfMails);
	        	if (image == null) {
	            	if( tmp_numberOfMails  > 0)
	            	{
		            	if (sendsSettings.autoOn()){
		                image = EncodedImage.getEncodedImageResource("yellowicon_home.png");
		            		
		                }
		            	else
		            	image = EncodedImage.getEncodedImageResource("redicon_home.png");
		            }
	            	else
	            	{            		
		                image = EncodedImage.getEncodedImageResource("greenicon_home.png");   
	            	}
	            	
	            }
	            if (appIcon == null) {
	                appIcon = new ApplicationIcon(image, true);
	            }
	           
	            appIndicatorRegistry = ApplicationIndicatorRegistry.getInstance();
	            
	          
	            appIndicator = appIndicatorRegistry.register(appIcon, false, true);
	            
	                     
	            mAppIndicator = appIndicatorRegistry.getApplicationIndicator();
	            
	            mAppIndicator.setIcon(appIcon);
	            
	            if( tmp_numberOfMails  > 0)            
	            	mAppIndicator.setValue(mailScreen.getNumberOfPendingMails ());
	           
	        	} catch (Exception ex) {
	        }
	    }
	
	    /**
	     * Method to remove application icon from home screen.
	     */
	    public static void resetBanner() {
	    	
	    	MailScreen mailScreen = new MailScreen(Application.getApplication());
	    	
	    	try{
	    	if (appIndicatorRegistry != null || mAppIndicator != null) {
	    		
	    		System.out.println("in reset banner  %%%%%%%%%%%%%%%");
	    		
	            appIndicatorRegistry.unregister();
	    		
	        }
	    	}catch(Exception e)
	    	{}
	    	appIndicatorRegistry = null;
	    	mAppIndicator = null;
	        appIcon = null;
	        image = null;

	    }

	    public Bitmap getAppIconImage()
	    {
	    	
	    	
	    	MailScreen mailScreen = new MailScreen(MailScreen.app.getApplication());
	    	FailedSendsSettings sendsSettings = new FailedSendsSettings(Application.getApplication());
	    	
	    	int tmp_numberOfMails = mailScreen.getNumberOfPendingMails ();
	    	
	    	Bitmap iconBitmap = new Bitmap(32, 32);
	    	Graphics g = new Graphics(iconBitmap);
	    	EncodedImage image = null;
	    	
	    	if( tmp_numberOfMails > 0 )
	    	{
	    		if (sendsSettings.autoOn())
	    		{
	    			 image = EncodedImage.getEncodedImageResource("yellowicon.png");
	    		}
	    		else
	    		{	
	    			 image = EncodedImage.getEncodedImageResource("redicon.png");
	    		}	
	    		g.drawImage(0, 0, 32, 32, image, 0, 0, 0);
    			g.setFont(g.getFont().derive(Font.FONT_INPUT_TEXT, Font.SIZE_SMALL));
    			g.setColor(Color.BLACK);
    			g.drawText(""+mailScreen.getNumberOfPendingMails(), 15, 23,0);
	    	}
	    	else //all mail sent
	    	{	
	    		if (sendsSettings.autoOn())
	    		{
	    			 image = EncodedImage.getEncodedImageResource("greenicon.png");   
	    		}
	    		else
	    		{
	    	    	 image = EncodedImage.getEncodedImageResource("yellowicon.png");  
	    		}
	    		g.drawImage(0, 0, 32, 32, image, 0, 0, 0);
	    	}
	    	return iconBitmap;
	    }
	
}

 

now i am using MessageListener to call this method code is here..

public class OutboxListener implements FolderListener, MessageListener {

	Message orginalMessage;
	Message [] outBoxedMessage;
	Message [] temp = null;
	Folder messageFolder;
	Folder outBox;
	Store store;
	
	
	public OutboxListener() {
		 try {
	        //retrieve the default message service          
			  
			 store = Session.getDefaultInstance().getStore();
	            //add the listener
	         store.addFolderListener(this);   
	         calculatePendingMails();
		 }catch (Exception e) {
			
		}
	            
	}
	
	public void messagesAdded(FolderEvent folderEvent) {		
        orginalMessage = folderEvent.getMessage();
        orginalMessage.addMessageListener(this);
        messageFolder = orginalMessage.getFolder();   
	}

	public void messagesRemoved(FolderEvent folderEvent) {		


	}

	public void changed(MessageEvent messageEvent) {
		 
		
		System.out.println("changed Status of Message of ID "+orginalMessage.getMessageId() + " "+"== "+orginalMessage.getStatus());
		
		if((orginalMessage.getStatus() == Message.Status.TX_ERROR )
				|| (orginalMessage.getStatus() == Message.Status.TX_GENERAL_FAILURE))
		{
			IconBanner iconBanner = new IconBanner();
			MailScreen mailScreen = new MailScreen(Application.getApplication());
			synchronized (net.rim.device.api.system.Application
      		      .getEventLock()) {
				calculatePendingMails();	
				HomeScreen.updateIcon(iconBanner.getAppIconImage());				
				IconBanner.resetBanner();
				IconBanner.setBanner();				
				}
		
		}		

	}
	
	
	public  Message [] calculatePendingMails()
	{
..................
// calclation code goes here
......................
	return outBoxedMessage;
	}

	public int setPendingMails() {		
		
		return MailScreen.mPendingMails = outBoxedMessage.length;
		
	}
	
}

 

 

Please help me ......

 

Thanks.

 

Kamalesh
Please use plain text.
Regular Contributor
kamaleshpandey
Posts: 91
Registered: ‎11-10-2009
My Device: BB 9810
My Carrier: Generic

Re: Status Indicator of My application is not refreshing from Background process

Hello,

 

If somebody help ?????

Kamalesh
Please use plain text.
Regular Contributor
kamaleshpandey
Posts: 91
Registered: ‎11-10-2009
My Device: BB 9810
My Carrier: Generic

Re: Status Indicator is not refreshing from Background process

 

Will Someone reply to my question?

OR does it seems too tough to solve ?

 

Kamalesh
Please use plain text.
Regular Contributor
kamaleshpandey
Posts: 91
Registered: ‎11-10-2009
My Device: BB 9810
My Carrier: Generic

Re: Status Indicator is not refreshing from Background process

WILL SOMEBODY HELP ???

Kamalesh
Please use plain text.
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.2174, Z10 (STL100-3)-10.3.0.700 Dev OS, Z30 (STA100-5)-10.3.0.700 Dev OS, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Status Indicator is not refreshing from Background process

I don't have any experience with the classes you are using so I can't really help you but most of the people who roam these forums do so either at night or on weekdays. Sorry.

 

I will just ask the generic questions that you will inevitably get asked at some point or another:

  • What OS are you running
  • What API did you use
  • Are you on the simulator or an actual device
  • Have you tried it on an actual device.
---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
Regular Contributor
kamaleshpandey
Posts: 91
Registered: ‎11-10-2009
My Device: BB 9810
My Carrier: Generic

Re: Status Indicator is not refreshing from Background process

Hi Rcmaniac,

 

Thanks for your response,

 

Here are the details go below what asked for:

 

1. The OS I am targeting is 4.6 onwards.

2. The API I used are:

 

net.rim.blackberry.api.messagelist.ApplicationIcon;
net.rim.blackberry.api.messagelist.ApplicationIndicator;
net.rim.blackberry.api.messagelist.ApplicationIndicatorRegistry;

 

3. I have tried it on both Simulator - 9000 and devices 9000/9650

 

But same result I am getting, its not refreshing the current indicator instead of its create a new indicator when running on background

 

 

Thanks,

Kamalesh
Please use plain text.
Administrator
MSohm
Posts: 14,297
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Status Indicator is not refreshing from Background process

You are registering a new icon every time the method is run.  Instead, you can re-use your existing registration by calling getApplicationIndicator (without first calling register).

 

Also note that calling Application.getApplication or UiApplication.getUiApplication may not return an instance of your application.  In the case of listeners, it'll return the application firing the listener and/or the application in the foreground.  This means you could be calling it from different applications, resulting in duplicate icons.

 

Here are some examples of creating a singleton application instance.

 

Create a singleton using the RuntimeStore

http://supportforums.blackberry.com/t5/Java-Development/Create-a-singleton-using-the-RuntimeStore/ta...

 

Allow a background listener to detect and update a GUI application

http://supportforums.blackberry.com/t5/Java-Development/Allow-a-background-listener-to-detect-and-up...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.