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
ravi1989
Posts: 773
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Re: Help me to save data in local storage.

why 

 

document.addEventListener("deviceready", onDeviceReady, false);

// Cordova is ready
//
function onDeviceReady() {

document.addEventListener("backbutton", function(e) {
alert("hi");
console.log("Back button pressed!!!!");
window.history.back();


}, false);

}

 

this is not working in android...:smileysad:

Please use plain text.
Developer
nunodonato
Posts: 313
Registered: ‎03-28-2012
My Device: Curve 9360, Playbook, BB10 Dev Alpha
My Carrier: TMN

Re: Help me to save data in local storage.

LBP, I'm like-ing all your replies just because I admire your patience so much :smileywink:

Nuno
theBBthing.wordpress.com - my BlackBerry development blog: news, tips and tutorials
bitoutsidethebox.com - re-imagining digital solutions


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

Re: Help me to save data in local storage.

Thanks sir

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: Help me to save data in local storage.

Hi Nuno. THX, it's just fun to answer :smileyvery-happy: but (@ravi1989) there are fundamental things like reading specs, reading API documentations, using Google or forum search before posting something here or in any other community forum.

 

@ravi1989: You should read and understand the Cordova/PhoneGap documentation for your backbutton event listener. All you need is in there. For the question about writing source code in HTML/JS/CSS I mainly use Notepad++ since I do not need a big IDE for most things. All you need is well documented frameworks and a knowledge about the things you are doing.

 

BTW: Working with Cordova/PhoneGap you need to use the different API implementations for the devices/OS? For every single supported device/OS they offer different .js framework files you need to use.


"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: Help me to save data in local storage.

sir it still not working back button in android.........:smileysad:

 

i used this code alert is not coming

 

document.addEventListener("backbutton", onBackKeyDown, false);

function onBackKeyDown() {
alert("gyu");
// Handle the back button
}

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: Help me to save data in local storage.

For Android development use Eclipse and the LogCat console to do some console.log or to get the errors in your app. The behaviour isn't really possible like you want it to work. In most cases the "back" button of the Android OS is bind to an OS functionality, so you can not really use it the way you want to without going into the Activity you are extending the DroidGap with.

 

BTW: Like many others mentioned before in this thread and also in many of the other threads you posted, this is a playground for BlackBerry devs in general. You might get an answer on your questions for whatever mobile OS you are referring to, but I think the first should be searching the web for your questions since almost all of them are already answered. And for your Cordova/Phonegap problems you can get an answer in the IRC or even in the Forum for it.

 

BTW2: Your problem might be an issue/bug of the Cordova/PhoneGap version you are using, the mobile OS version you run into an issue or you can find your answer in the forum post here by reading and understanding the provided source code. All you need should be in there.


"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: Help me to save data in local storage.

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.
Developer
Developer
LBP
Posts: 607
Registered: ‎04-29-2011
My Device: PlayBook 16GB, BB10 LE Z10 (red)
My Carrier: none

Re: Help me to save data in local storage.

Strange issue. Is there any line number reported with the "JSON undefined" output?


"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: Help me to save data in local storage.

1 sec i will tell you

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

Re: Help me to save data in local storage.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Select Arrival Station</title>
<link href="style/style.css" rel="stylesheet" type="text/css" />
<link href="style/scrollpanel.css" rel="stylesheet" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<script language="javascript" type="text/javascript" src="script/actb.js"></script>
<script language="javascript" type="text/javascript" src="script/actb2.js"></script>
<script type="text/javascript" src="script/common.js"></script>
<script type="text/javascript" src="script/soapclient.js"></script>
<!--script type="text/javascript" src="cordova-1.9.0.js"></script-->
<script type="text/javascript">

    
        var stationList = new Array;	
        
          
   		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);
		}
		}


		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;
	          	
          	}
          	
		}
      
		function displayAllStation(){
            if(document.getElementById('getStationDesc').value!=""){

			
			window.location="arrival.html?getStationCode="+document.getElementById('getStationCode').value+"&getStationDesc="+document.getElementById('getStationDesc').value;
            }
            else{
                
                alert("Please select station.");
            }
			
			
		}
		
		function displayNextStation(){
            if(document.getElementById('getStationDesc').value!=""){
			
			window.location="nextarrivalstation.html?getStationCode="+document.getElementById('getStationCode').value+"&getStationDesc="+document.getElementById('getStationDesc').value;
            }
            else{
                
                alert("Please select station.");
            }
			
			
		}



</script>
</head>
<body onload="GetStationCodes()">
<div id="wrapper">
  <div class="departure_cont">
    <div class="home_icon"><a href="index.html"><img src="images/home-icon.png" alt="Home" title="Home" /></a></div>
    <h1 class="fr">Arrivals</h1>
    <div class="cl"></div>
    <h2 id="headingcontent"></h2>
    <div class="cl"></div>
    <ul>
 
      <li>
        <button type="submit" class="btn" id="submitBtn1" >Get Date</button>
      </li>
      <li>
        <button type="submit" id="submitBtn2" class="btn" onclick="FillValues();displayNextStation()" disabled="disabled">Next Train</button>
      </li>
      <li>
        <button type="submit" id="submitBtn3"  class="btn" onclick="FillValues();displayAllStation()" disabled="disabled">All today</button>
      </li>
    </ul>
    <h3 style="text-align:left; float:left; margin-left:3%;">Change Location</h3>
    <div class="cl"></div>
    <form name="frmIndex" type=get>
      <div class="log_cont">
        <input id="getStationDesc" name="getStationDesc" type="text" class="log_txtfield" disabled="disabled"/>
        <script>
					   var obj = actb(document.getElementById('getStationDesc'),stationList);
						//$("#index").trigger("pagecreate");
						//setTimeout(function(){obj.actb_keywords = custom2;},10000);
						
						this.actb_timeOut = -1;
						// Number of elements autocomplete can show (-1: no limit)
						this.actb_lim = 10;
						// should the auto complete be limited to the beginning of keyword?
						this.actb_firstText = true;
						// Enable Mouse Support
						this.actb_mouse = true;
						// Delimiter for multiple autocomplete.
						// Set it to empty array for single autocomplete
						this.actb_delimiter = new Array(' ',',');
						// Show widget only after this number of characters is typed in.
						this.actb_startcheck = 1;
						
		
				this.actb_bgColor = '#dbe3ec';
						this.actb_textColor = '#00256a';
						this.actb_hColor = '#dbe3ec';
						this.actb_fFamily = 'arial';
						this.actb_fSize = '16px';	
						this.actb_hStyle = 'text-decoration:underline;font-weight="bold;";text-align="left"';
						
						function FillValues()
						{
							
							document.getElementById('getStationCode').value = document.getElementById('getStationDesc').value.substring(0,3);	
							if(window.localStorage.getItem("lastArrivalStation")!=null){
									window.localStorage.removeItem("lastArrivalStation");
								}
							
								window.localStorage.setItem("lastArrivalStation",document.getElementById('getStationDesc').value);
									
						}
					</script>
        <div> <img src="images/ajax-loader.gif" id="loadingImg" visible =true style="margin:auto; position: absolute; left:50%; top:50%;"/> </div>
        <input id="getStationCode" name="getStationCode" type="hidden" />
      </div>
    </form>
  </div>
</div>
</body>
</html>

 This is my code...LIne number 22

 

var r = JSON.parse(window.localStorage.getItem("stations"))||[];

Please use plain text.