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

Web and WebWorks Development

Reply
Developer
Developer
LBP
Posts: 607
Registered: ‎04-29-2011
My Device: PlayBook 16GB, BB10 LE Z10 (red)
My Carrier: none

Re: how to store data same as persistence in Blackberry in phonegap

[ Edited ]

NitishSubudhi wrote:

Well I am not sure about the data deletion of localStorage after the device restart.
But I have read somewhere That LocalStorage Store The data for the same instance. And If the device or system will restart then all the storage data will be vanish. 


That wouldn't be a good thing if localStorage will be deleted or vanish when you restart the device. The apps I'm working on make use of localStorage and it isn't deleted after a restart. As far as I know localStorage and openDatabase is persistent storage mechanisms whereas sessionStorage is only available while app is running.


"Like" if you liked the post.
"Accept as Solution" if the post solves your question.
Please use plain text.
Developer
ravi1989
Posts: 773
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Re: how to store data same as persistence in Blackberry in phonegap

i attached my whole code..
Please use plain text.
Developer
ravi1989
Posts: 773
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Re: how to store data same as persistence in Blackberry in phonegap

Hi 

 

I Attached my whole code.In my application every time i call web service to download station list,   but i don't want this.I just want only first time i want to download station list  from . then list i store this list in persitance or HTML5 , show list from persistance or HTML5 database .

I am beggineer can you please help me.

 

 

Thanks

 

Please use plain text.
Developer
ravi1989
Posts: 773
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Re: how to store data same as persistence in Blackberry in phonegap

Please help me to store data....
Please use plain text.
Developer
Developer
LBP
Posts: 607
Registered: ‎04-29-2011
My Device: PlayBook 16GB, BB10 LE Z10 (red)
My Carrier: none

Re: how to store data same as persistence in Blackberry in phonegap

The easiest way to store data is using localStorage together with data objects in JSON format:

 

/* store objects in JSON format to localStorage */
localStorage.setItem("myData", JSON.stringify(data));

/* load objects from localStorage */
var data = JSON.parse(localStorage.getItem("myData"));

 


"Like" if you liked the post.
"Accept as Solution" if the post solves your question.
Please use plain text.
Developer
ravi1989
Posts: 773
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Re: how to store data same as persistence in Blackberry in phonegap

Hi

 

Your code is working Fine in IOS

Bus there is problem in Android i don't know why this problem occur.?

 

<body onload="GetStationCodes()">

function GetStationCodes()
  		{    
	  		var r = JSON.parse(window.localStorage.getItem("stations"))||[];
	  		if(r.length > 0){
                document.getElementById('loadingImg').style.visibility = "hidden";
                document.getElementById('submitBtn1').removeAttribute('disabled');
                document.getElementById('submitBtn2').removeAttribute('disabled');
                document.getElementById('submitBtn3').removeAttribute('disabled');
                document.getElementById('getStationDesc').removeAttribute('disabled');
                if(window.localStorage.getItem("lastArrivalStation")!=null){
                    document.getElementById("headingcontent").innerHTML =window.localStorage.getItem("lastArrivalStation");   
                }
                else{
                    document.getElementById("headingcontent").innerHTML = "No station is selected."; 
                }
                for (var i = 0; i < r.length-1; i++)
                {
                    stationList[i] = r[i].stationCode + " - " + r[i].stationName;
                }
                
            } 
            else {
	  		document.getElementById('loadingImg').style.visibility = "visible"; 
	  		
		     var pl = new SOAPClientParameters();
		     var parameter1 = "";
		     var parameter2 = "";
		     pl.add("parameter1", parameter1);
		     pl.add("parameter2", parameter2);
		     document.getElementById("headingcontent").innerHTML = "No station selected.";
		     SOAPClient.invoke(WSDLURL, "stationSearch", pl, true, GetStationCodes_callBack);
		}
		}


i save here stations


function GetStationCodes_callBack(r)
 		{ 
	 		
	 		document.getElementById('loadingImg').style.visibility = "hidden";
	 		document.getElementById('submitBtn1').removeAttribute('disabled');
			document.getElementById('submitBtn2').removeAttribute('disabled');
			document.getElementById('submitBtn3').removeAttribute('disabled');
			document.getElementById('getStationDesc').removeAttribute('disabled');
            window.localStorage.setItem("stations", JSON.stringify(r));
			for (var i = 0; i < r.length-1; i++)
          	{
	          	stationList[i] = r[i].stationCode + " - " + r[i].stationName;
	          	
          	}
          	
		}

 Error is : JSON is undefined

Please use plain text.