Having trouble with SQLite and local storage in Android PhoneGap app specifically on Samsung Galaxy devices

My PhoneGap app is running smoothly on iOS and most Android devices, but I'm encountering an issue specifically with Samsung Galaxy S3 and S4.

Upon the initial page load, the app creates a local SQL database to store question and answer values. However, on the Samsung devices, the database fails to load properly the first time the app is launched. Subsequently, if the user exits the app completely and relaunches it, the database is created without any errors. Since the first page of the app requires users to input their age, which is then stored in the SQL database, they are mistakenly assuming that the app has frozen at this stage.

The database initialization code is as follows:

index.html

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

function onDeviceReady() {
    populateDB(); 
}
...

Following the age_button_pressed function, there is no further progress and the database does not update accordingly.

This issue seems to be specific to Samsung Galaxy S3 and S4, leading me to speculate whether Samsung's WebKit is contributing to the problem.

Answer №1

The issue could possibly be due to opening the database multiple times. Ensure that you only open it once and perform all transactions on that same instance. Additionally, confirm that any previous transaction has completed before initiating a new one. While it's unexpected, based on my encounters, Cordova's (PhoneGap) WebSQL can be a little unpredictable.

Answer №2

My experience with phonegap was smooth from version 2.0 to 3.1 on Samsung and HTC devices, without encountering any major issues. Which version of phonegap are you currently using? I recommend sticking to stable versions rather than beta releases.

One possible reason for your problem could be a synchronization issue on app startup. To troubleshoot, try adding the deviceready event in your index.html file and then redirecting to your main page. Perform database operations like table creation and data insertion on this main page.

Additionally, make sure to monitor error messages in the errorCB function. This function receives a parameter containing an error code and message that can provide insights into the issue at hand.

If you're using a Samsung Galaxy S4 with Android 4.4, consider leveraging Chrome for debugging your JavaScript code. Debugging capabilities in phonegap, especially when used with Chrome, can greatly facilitate troubleshooting.

Answer №3

In my opinion, the issue may not lie with the device itself but rather with it being overloaded. One solution could be to try executing each database order sequentially, using callbacks:

DB.transaction(
  function(tx){
     tx.executeSql("CREATE TABLE IF NOT EXISTS SessionData (\n\
        id INTEGER PRIMARY KEY,\n\
        field1 TEXT NOT NULL,\n\
        field2 TEXT NOT NULL)");
  },
  function(err){
    console.log("Error code: "+err.code);
  },
  function(){
      DB.transaction(function(tx){
         tx.executeSql("CREATE TABLE IF NOT EXISTS Table2 (\n\
          id INTEGER PRIMARY KEY,\n\
          field1 TEXT NOT NULL,\n\
          field2 TEXT NOT NULL)");
      },
      function(err){
          console.log("Error code: "+err.code);
      },
      function(){
      });
  });

Answer №4

Experiment with a larger database size, increasing it from 20000 to 200000

var db = window.openDatabase("Database", "1.0", "My Database", 200000);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can files be saved using AngularJS JavaScript with Windows-1250 encoding?

I am currently working on a web application using AngularJS and SpringBoot API REST. My challenge involves calling a REST API with a GET request to retrieve a flow of text data, and then attempting to save this data in a file with the charset WINDOWS-125 ...

Is it possible to access the HTML code of an app that uses a WebView?

I recently came across a stunning android application and I am eager to explore its source code. I have observed that the app has been created using webview technology. ...

Ways to substitute the $(document).ready function?

I'm facing a problem and struggling to find a solution. Here is the JavaScript script that's causing me trouble: $(function () { $.ajaxSetup({ cache: false }); var timer = window.setTimeout(function () { $(".alert").fadeTo(10 ...

Troubleshooting Problem with GenyMotion Alert Dialog on Android

I am a beginner in android programming and I am working on creating an alert dialog project. My XML file seems to be correct, but when I run the app on Genymotion, the alert dialog does not appear. Here are my java codes: package karimi.afshin.alertdialog ...

android datepicker without using the dialog

Currently, I'm attempting to show a date (in text format) that has been selected using a "datepicker" on a textview. I want the textview to be updated whenever the date in the date picker changes, and I would like to display the date in long format (e ...

Ensuring proper execution of the next callback function in an Express get request

I am currently running an express server on nodejs with a specific file structure that I need to convert into a list of links. Included below are my recursive functions for dealing with the file structure. Here are the file structure functions: function ...

How can I create reactivity for this hook in Vue 3?

So here's the deal, I have this hook code snippet that goes like this: export const useOpeningHours = ( flight: Ref<FlightOption | null>, identifier: string, isEnabled?: boolean ) => { if (!flight.value) { return { show: fa ...

Determining Equality in JavaScript: Comparing 2 Objects

I'm currently working with 2 objects that will always have the same amount of properties, but their values may vary. In my attempt to check if the two objects hold the same values, I decided to use the .every method. However, all results are returnin ...

Gaps and Islands Using Start and End Dates (Validity Periods)

I have been looking everywhere but cannot find a solution to the problem at hand. Within several massive price lists containing millions of rows, I have noticed some instances where multiple examples can be combined into one row due to consecutive start a ...

A different approach to fixing the error "Uncaught (in promise) TypeError: fs.writeFile is not a function" in TensorFlow.js when running on Chrome

I've been attempting to export a variable in the TensorFlow posenet model while it's running in the Chrome browser using the code snippet below. After going through various discussions, I discovered that exporting a variable with fswritefile in t ...

The 'xxx' type does not have an index signature, so the element is implicitly assigned an 'any' type

I'm currently facing an issue with TypeScript. The error message I'm encountering is related to the following section of code: The Interface: export default interface IUser { username: string; email?: string; isActive: boolean; group: s ...

When the "change" event listener is added to an input element, the innerHTML is updated as the value increases but not when it decreases

My div block contains a value that I need to adjust as the input value changes. While the adjustment works when the input value increases, it does not change when the input value is decreased. It seems like there may be an oversight in my logic that I am m ...

Detect Flash Player Event using Javascript

Is there a way to detect when a flash video ends without depending on user input like clicking the stop button? It's important to note: I HAVE NO CONTROL OVER THE PRESENTATIONS OR SWF FILES. My goal is to automate the client player object through s ...

The TextFieldParser is having difficulty parsing the final line

Currently, I am importing a .csv file into my SQL database using TextFieldParser. This is the code snippet I am utilizing: TextFieldParser parser = new TextFieldParser(file); parser.TextFieldType = FieldType.Delimited; parser.SetDelimiters(","); int k ...

Is it considered acceptable to house a myriad of variables within the token object in NodeJS?

Currently working on implementing authentication with NodeJS, expressJS, mongodb and React Native. Is it acceptable to include multiple variables in the token object like shown in this example? const token = jwt.sign( { userId: user. ...

Issue with window.location.href and unexpected behavior in Firefox 7

I can't seem to figure out the issue I'm encountering on FF7 My ajax calls are returning a json object (jquery). if(data.result=='ok') { var url = baseURL + "azioni/makeForm/" + data.actcode + "/DIA/" + data.az_id; console.log ...

Content not being displayed by ng-repeat

Currently, I am in the process of developing a web application using Node.js with Express serving as the backend and HoganJs as the templating engine, while AngularJS is being utilized on the frontend. However, I have encountered an issue where the ng-repe ...

Retrieve specific information from checkboxes within a form

I'm working on a form that includes multiple checkboxes populated with data from a JSON file using ng-repeat. After submitting the form, I need to retrieve the data from the checked checkboxes. How can I accomplish this in my controller after the form ...

Conceal a div once the user scrolls to a certain position using vanilla JavaScript

As a beginner in the field of web development, I am currently working on creating a blog website. Code Function - One of the challenges I'm facing is implementing a floating pagination bar that needs to be hidden when a visitor scrolls near the foote ...

React Native Application in the Absence of Reliable Internet Connectivity

I am currently facing an issue with my React Native app that heavily depends on a stable internet connection. The app features a questionnaire function that is working properly. However, there is one specific functionality where users need to upload an aud ...