Customize JavaScript code loaded from a local static HTML file based on user selection from a list in a prior activity on Android

As a newcomer to the world of Android and Java, I greatly appreciate your patience in advance!

I'm currently faced with the challenge of passing a file path (which could be a simple string or integer) from an activity written in Java to a WebView that is rendering a static local html file running JS. The complexity arises due to my use of an AR SDK (Wikitude) which requires their own custom WebView (including a CameraSurfaceView) - control over this suite is managed by a JS file loaded by the html document.

I'm open to any solutions as I am unfamiliar with Android development and unsure where to start on this issue. Essentially, I want to select an option in one activity and relay that information to my JS file for loading/rendering assets. In a web app, you could use templating to insert dynamic variables into your html (e.g. erb in ruby or moustache in JS).

If there's no direct way to template Java into a JS file, my current idea involves writing a JSON object using JsonWriter in the activity and then loading that file in the JS. However, I'm struggling to understand how to manage internal/external storage in Android in relation to the assets folder of my app - any guidance on this would be much appreciated.

This explanation is kept intentionally broad, but I can provide code upon request.

Answer №1

When transitioning from one activity to another, you have the option to carry over selected data by utilizing the following method.

//Initiating a new activity

Intent intent = new Intent(MainActivity.this, Second_Activity.class);

Include the data within the intent

intent.putExtra("choice1", "chosen_option_1");
intent.putExtra("choice2", "chosen_option_2");
startActivity(intent); 

In the onCreate() method of the second activity, extract this data from the intent as demonstrated below:

String choice1 = getIntent().getStringExtra("choice1");

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

Making a JSON POST request from an Android device

As a beginner in Android development, I have learned that the method for sending post requests is deprecated in Android 22 and later versions. Can anyone provide a sample of working Android code using the URLCONNECTION method to send a JSON POST request ...

PhantomJS: Saving SVG for Future Use

I am attempting to save an SVG file from a sample testpage using PhantomJS. I have successfully navigated to the testpage, but I am unsure of how to locate and save the SVG element. Below is my current approach and where I am encountering difficulties. V ...

onload function prevents further URL redirection

After submitting the form "View this product," a function is triggered to retrieve the product id from the form data. Although I can successfully obtain the form_data, the page does not redirect as expected. I suspect that my function may not have been pr ...

Using JQuery to extract the value of cells

How to retrieve cell values using JQuery? I attempted the following code: $("#table tr").each(function(){ var result = $(this).find("td:first").html(); alert(result); }); However, instead of individual values, it returns a string comprising all ...

Not all records are compatible with PHP Echo when placed within a paragraph

Looking for some assistance with a simple form set up; <div class="formholder"> <form action="column1.php" method="post"> <input type="text" placeholder="URL:" name="url" required=""><br> <input type="t ...

What is the best way to output multiple values from a PHP script to a JavaScript Ajax request?

Looking at the code provided below, I am trying to access variables that have been initialized in my processUsersAnswers.php file from my index.php file. Code snippet within index.php <script type="text/javascript"> function checkAnswers(){ va ...

When utilizing data-ng-view, AngularJS struggles to locate the corresponding HTML content

I am currently working on building an application using AngularJS, MVC, and API. Below you can find the code for my AngularJS module and controller: //home-index.js var myApp = angular.module('myApp', []); myApp.config([function ($routeProvider) ...

Mastering React.js: How to Efficiently Pass Parameters to Event Handlers in Components without Using bind()

When utilizing a event handler that uses the keyword this (such as in the example handleClick using this.setState), it is necessary to bind the event handler with the keyword this. If not, you can utilize the arrow function. For instance: //Although this ...

Encountered an issue while trying to build helloJni using Android NDK nd

I am attempting to run the HelloJni program from the NDK samples using Eclipse Juno. However, the ".so" file is not being generated. When I run ndk-build on the project, I receive the following message in my console: **** Build of configuration Default ...

Creating hyperlinks in JSON response from a REST API with AngularJS - A guide!

I have a web application built with AngularJS, JS, JQ, and HTML5. This app can send various HTTP methods to the project's RESTful Web Service and receive responses in JSON format. The response is structured like this: When displayed in a <pre> ...

Tips for retrieving hidden table data with xpath on selenium webdriver using Java

I am facing a challenge in extracting the values from the "From" dropdown menu on . The dropdown appears to be hidden and is an autocomplete feature. My goal is to compare these extracted values with a specific search string to determine its presence withi ...

Is there a way to access and view all cache in Http using AngularJS?

There is a method that I know how to use var cache = $cacheFactory.get('$http'); cache.get('http://example.com/api/users.json'); I am curious about what other information the data cache contains. I attempted console.log(cache) but i ...

Running a task in an activity from the application class

I am exploring ways to automate the execution of an AsyncTask rather than relying on a button press trigger. Some background information - Application Class // The Handler responsible for receiving data from BluetoothService public final Handler mHandle ...

React - Login page briefly appears while loading

Hello, I have built a React application that consists of a Login page, Loading page, and the main app itself. However, there is a small issue where after a user logs in, instead of smoothly transitioning to the Loading page until the data is loaded, the L ...

Steps for executing various tasks and selecting the hyperlink labeled Member Login located at http://www.spicejet.com/ using selenium-webdriver

https://i.sstatic.net/UGhiN.jpg I attempted to use the following code, but it does not seem to perform a mouse hover and click on 'Member login' WebElement lgn = driver.findElement(By.id("ctl00_HyperLinkLogin")); WebElement ssm = driver.findEle ...

Turn off Drag and Drop Feature for jQuery File Upload

Currently, I have implemented an ajax file uploader on my website using the following plugin: https://github.com/blueimp/jQuery-File-Upload On one of my pages, there are two controls for uploading files - one for images and another for documents. Both con ...

Finding the Text of an HTML Element

I need to retrieve the text content from an HTML element. For example, if I have <p>ABCD</p> I want the output to be ABCD It would look something like this: var html='<p>ABCD</p>'; var str = extractText(html); I belie ...

Changing the color of specific sprites in three.js

I'm currently exploring three.js and encountering some difficulties when attempting to adjust the color of individual sprites in an array. My reference point is the example provided on this link from threejs.org. The specific task I am working on in ...

I'm having trouble with my .Refine feature when attempting to create a conditional input field. Can anyone help troubleshoot this issue?

I devised a feature in my form that generates additional input fields if the user selects 'yes'. How can I make these input fields mandatory and display a warning message when 'yes' is selected? const FormSchema = z.object({ type: z.e ...

Creating and maintaining a table in AngularJS based on specific tag values

Hello, I am new to working with AngularJS and have come across a scenario that I need help with. My goal is to create a table with multiple tbody elements (which are essentially rows, but using tbody for optimal functionality with angularjs 1.0.7). Each ...