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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Regular Contributor
Posts: 96
Registered: ‎06-09-2011
My Device: sdk 9800
My Carrier: java development

How to update(or refresh) previous instance screen ?

Hi,

in my application i have a counter, when i click add to cart button the counter value should be increment,when ever i click the back button i used to get the previous screen and i am getting that my problem is if the counter value is 1 in the previous screen i am getting 1 insted of that i used to get the actual value.....

 

in short my previous screen should be refreshed when i click on back button

 

plese help me.....

Press the Kudos button (star) on the left side to thank and
please mark the Thread as solved if its solved...


Thanks and Regards
Nagarjuna
Developer
Posts: 404
Registered: ‎05-31-2011
My Device: curve
My Carrier: devel

Re: How to update(or refresh) previous instance screen ?

hey, you must override the onClose() method
public boolean onClose()
{
UiApplication.getUiApplication().pushScreen(new prviews_screen());
return true;
}
Contributor
Posts: 46
Registered: ‎07-07-2011
My Device: 9800
My Carrier: BlackBerry

Re: How to update(or refresh) previous instance screen ?

Ya , above one is appropriate one
Developer
Posts: 404
Registered: ‎05-31-2011
My Device: curve
My Carrier: devel

Re: How to update(or refresh) previous instance screen ?

you can click on mark as solution and give a kudos if your pb is resolved
Regular Contributor
Posts: 96
Registered: ‎06-09-2011
My Device: sdk 9800
My Carrier: java development

Re: How to update(or refresh) previous instance screen ?

Sorry it is not working ,please tell me if any other way

Press the Kudos button (star) on the left side to thank and
please mark the Thread as solved if its solved...


Thanks and Regards
Nagarjuna
Developer
Posts: 404
Registered: ‎05-31-2011
My Device: curve
My Carrier: devel

Re: How to update(or refresh) previous instance screen ?

put your code to know what's the pb
Regular Contributor
Posts: 96
Registered: ‎06-09-2011
My Device: sdk 9800
My Carrier: java development

Re: How to update(or refresh) previous instance screen ?

tell me any otherway or where should i override the onclose method
Press the Kudos button (star) on the left side to thank and
please mark the Thread as solved if its solved...


Thanks and Regards
Nagarjuna
Developer
Posts: 404
Registered: ‎05-31-2011
My Device: curve
My Carrier: devel

Re: How to update(or refresh) previous instance screen ?

you should override in class 2 who call the previous_screen when click on the back button
Regular Contributor
Posts: 96
Registered: ‎06-09-2011
My Device: sdk 9800
My Carrier: java development

Re: How to update(or refresh) previous instance screen ?

public class Details extends MainScreen 
{
	 JSONObject obj;
	 	 public Details(String object, JSONArray json) throws JSONException, IOException 
{
		 invalidate();
			HorizontalClass horizontalClass=new HorizontalClass();
			setStatus(horizontalClass.adjust(MyScreen.totalItems));
         this.setTitle(AppScreen.setTitle1(object));
         this.setBanner(AppScreen.setBanner());
		 final JSONArray arr=json;
		 for(int i=0;i<arr.length();i++){
			Font myFont = Font.getDefault().derive(Font.ITALIC, 6, Ui.UNITS_pt);
			obj=arr.getJSONObject(i);
			if(object.equals(obj.get("name")))
			{
             HorizontalFieldManager hfm=new HorizontalFieldManager();
         			    
			    try
				{
					HttpConnection connection=(HttpConnection)Connector.open(obj.getString("imageUrl"));
					int response=connection.getResponseCode();
					if(response==HttpConnection.HTTP_OK)
					{
						InputStream is=connection.openInputStream();
						int length1=is.available();
						byte[] data=new byte[length1];
						data=IOUtilities.streamToBytes(is);
						is.close();
						connection.close();
						Bitmap image=Bitmap.createBitmapFromBytes(data,0,data.length,1);
						BitmapField field=new BitmapField(Scale.resizeBitmap(image, 110, 250),Field.FOCUSABLE);
						hfm.add(field);
					}
				}
				catch (Exception e) {
					System.out.println("Exception From Thread"+e);
				}
				HorizontalFieldManager hfm1=new HorizontalFieldManager();
					BrowserField bfield=new BrowserField();
				bfield.displayContent("<font size='1'/>"+obj.getString("description"), "http://localhost");
				bfield.setFont(myFont);
				String price=obj.getString("price");
				
				final JSONObject pobj=new JSONObject(price);
				LabelField lf=new LabelField("Sale Price: $"+pobj.get("sale"))
				{
					public void paint(Graphics graphics)
				    {
				        graphics.setColor(Color.RED);
				        
				        super.paint(graphics);
				    }
				};
				
				ButtonField button=new ButtonField("Add to Cart",Field.FOCUSABLE){
				
					protected boolean navigationClick(int status,int time){
						
						JSONArray jsonarray1=new JSONArray();
						boolean flag=true;
						for(int c=0;c<10;c++){
							try{
								
								
							JSONObject json1=MyScreen.jsonarray.getJSONObject(c);
							int quantity=MyScreen.jsonarray.getJSONObject(c).getInt("quantity");
							if(json1.getString("imageUrl")==obj.getString("imageUrl")){
								
							flag=false;
						    
							JSONObject jsonobject3=new JSONObject();
							
							jsonobject3.put("name",obj.getString("name"));
							jsonobject3.put("price",obj.getString("price"));
							jsonobject3.put("imageUrl", obj.getString("imageUrl"));
							
							jsonobject3.put("quantity",(quantity+1));
							jsonarray1.put(jsonobject3);
							
							Dialog.alert("This item already added to cart");
							}
							else{
								
							jsonarray1.put(MyScreen.jsonarray.getJSONObject(c));
							
							}
							}catch(JSONException e){
								
							}
							
						
						   }
						 if(flag){
							 try{
								int quantity=1;
							    JSONObject jsonobject=new JSONObject();
								jsonobject.put("name",obj.getString("name"));
								jsonobject.put("price",obj.getString("price"));
								jsonobject.put("imageUrl", obj.getString("imageUrl"));
							    jsonobject.put("quantity", quantity);
							    MyScreen.jsonarray.put(jsonobject);
							 }catch(JSONException e){}
							 
							
						 }else{
							
							 MyScreen.jsonarray=null;
							 MyScreen.jsonarray=jsonarray1;
						   
						 }
						 MyScreen.totalItems=MyScreen.totalItems+1;// here my variable is updating this i am inserting in the label field
						
						 UiApplication.getUiApplication().popScreen(Ui.getUiEngine().getActiveScreen());
						 UiApplication.getUiApplication().pushScreen(Ui.getUiEngine().getActiveScreen());//when i get this screen my screen is previous instance which  was not updated or refreshed
						 return true;
					}
				};
			
			
				hfm.add(bfield);
				add(hfm);
				hfm1.add(button);
				hfm1.add(lf);
				add(hfm1);
				
				
				break;
			}
	
		}
		
	}
	

}

 

 

Press the Kudos button (star) on the left side to thank and
please mark the Thread as solved if its solved...


Thanks and Regards
Nagarjuna
Developer
Posts: 404
Registered: ‎05-31-2011
My Device: curve
My Carrier: devel

Re: How to update(or refresh) previous instance screen ?

if this is the actualy screen and you want to go back from this screen to preview_screen you can add onClose like this:

public class Details extends MainScreen 
{
	 JSONObject obj;


public boolean onClose()
       {           
            uiapp.getUiApplication().pushScreen(new preview_screen());      
            return true;
       }


	 	 public Details(String object, JSONArray json) throws JSONException, IOException 
{
		 invalidate();
			HorizontalClass horizontalClass=new HorizontalClass();
			setStatus(horizontalClass.adjust(MyScreen.totalItems));
         this.setTitle(AppScreen.setTitle1(object));
         this.setBanner(AppScreen.setBanner());
		 final JSONArray arr=json;
		 for(int i=0;i<arr.length();i++){
			Font myFont = Font.getDefault().derive(Font.ITALIC, 6, Ui.UNITS_pt);
			obj=arr.getJSONObject(i);
			if(object.equals(obj.get("name")))
			{
             HorizontalFieldManager hfm=new HorizontalFieldManager();
         			    
			    try
				{
					HttpConnection connection=(HttpConnection)Connector.open(obj.getString("imageUrl"));
					int response=connection.getResponseCode();
					if(response==HttpConnection.HTTP_OK)
					{
						InputStream is=connection.openInputStream();
						int length1=is.available();
						byte[] data=new byte[length1];
						data=IOUtilities.streamToBytes(is);
						is.close();
						connection.close();
						Bitmap image=Bitmap.createBitmapFromBytes(data,0,data.length,1);
						BitmapField field=new BitmapField(Scale.resizeBitmap(image, 110, 250),Field.FOCUSABLE);
						hfm.add(field);
					}
				}
				catch (Exception e) {
					System.out.println("Exception From Thread"+e);
				}
				HorizontalFieldManager hfm1=new HorizontalFieldManager();
					BrowserField bfield=new BrowserField();
				bfield.displayContent("<font size='1'/>"+obj.getString("description"), "http://localhost");
				bfield.setFont(myFont);
				String price=obj.getString("price");
				
				final JSONObject pobj=new JSONObject(price);
				LabelField lf=new LabelField("Sale Price: $"+pobj.get("sale"))
				{
					public void paint(Graphics graphics)
				    {
				        graphics.setColor(Color.RED);
				        
				        super.paint(graphics);
				    }
				};
				
				ButtonField button=new ButtonField("Add to Cart",Field.FOCUSABLE){
				
					protected boolean navigationClick(int status,int time){
						
						JSONArray jsonarray1=new JSONArray();
						boolean flag=true;
						for(int c=0;c<10;c++){
							try{
								
								
							JSONObject json1=MyScreen.jsonarray.getJSONObject(c);
							int quantity=MyScreen.jsonarray.getJSONObject(c).getInt("quantity");
							if(json1.getString("imageUrl")==obj.getString("imageUrl")){
								
							flag=false;
						    
							JSONObject jsonobject3=new JSONObject();
							
							jsonobject3.put("name",obj.getString("name"));
							jsonobject3.put("price",obj.getString("price"));
							jsonobject3.put("imageUrl", obj.getString("imageUrl"));
							
							jsonobject3.put("quantity",(quantity+1));
							jsonarray1.put(jsonobject3);
							
							Dialog.alert("This item already added to cart");
							}
							else{
								
							jsonarray1.put(MyScreen.jsonarray.getJSONObject(c));
							
							}
							}catch(JSONException e){
								
							}
							
						
						   }
						 if(flag){
							 try{
								int quantity=1;
							    JSONObject jsonobject=new JSONObject();
								jsonobject.put("name",obj.getString("name"));
								jsonobject.put("price",obj.getString("price"));
								jsonobject.put("imageUrl", obj.getString("imageUrl"));
							    jsonobject.put("quantity", quantity);
							    MyScreen.jsonarray.put(jsonobject);
							 }catch(JSONException e){}
							 
							
						 }else{
							
							 MyScreen.jsonarray=null;
							 MyScreen.jsonarray=jsonarray1;
						   
						 }
						 MyScreen.totalItems=MyScreen.totalItems+1;// here my variable is updating this i am inserting in the label field
						
						 UiApplication.getUiApplication().popScreen(Ui.getUiEngine().getActiveScreen());
						 UiApplication.getUiApplication().pushScreen(Ui.getUiEngine().getActiveScreen());//when i get this screen my screen is previous instance which  was not updated or refreshed
						 return true;
					}
				};
			
			
				hfm.add(bfield);
				add(hfm);
				hfm1.add(button);
				hfm1.add(lf);
				add(hfm1);
				
				
				break;
			}
	
		}
		
	}
	

}