Android: retrieving data bundle within another fragment activity - android-activity

I am trying to retrieve some data in a bundle created within one activity from another fragment activity
Data is entered into the first screen, then the next screen (containing the fragment) retrieves it via activityCallbacks.
I can't even get the parent activity of the second screen to return my data.
Am i doing this right?
In the first screen, the data is packaged into a bundle as follows:
Bundle dataBundle = new Bundle();
dataBundle.putInt("myInt", 9);
I have tried this in the parent activity of the second screen i am using:
Bundle myBundle = getIntent().getExtras();
tvDBG = (TextView) findViewById(R.id.tvDBG);
tvDBG.setText(""+myBundle.getInt("MyInt"));
This is just causing a crash.
should i be using the asset manager instead and if so how?

Bundle bundle=getArguments();
int mvalue = bundle.getInt("myInt", 0);
you also check spelling for "myInt"

Related

How to retrieve AssetReference from Scene?

I have a Scene marked as Addressable. Given the Scene itself, is it possible to get the AssetReference for that scene?
For example, in the following code snippet, what would ?? need to be?
Scene activeScene = SceneManager.GetActiveScene();
// What can I call here to get the AssetReference?
AssetReference activeSceneReference = ??;
If this is possible at all I honetsly can't tell since I never worked with Addressables so far.
However, following the APIs this might be possible but requires multiple steps:
Since the activeScene is a loaded scene and the same scene can be loaded multiple times via additive loading it is not actually an asset anymore and therefore doesn't have an asset reference at all.
So the first step is actually
Get the asset for a loaded scene
Having your loaded scene you can still get its original asset path via Scene.path.
var activeScene = SceneManager.GetActiveScene();
var activeScenePath = activeScene.path;
And then use AssetDatabase.LoadAssetAtPath to load the original asset
var activeSceneAsset = AssetDataBase.LoadAssetAtPath<Scene>(activeScenePath);
Now that we have the actual asset of the loaded scene we can
Get the GUID of an Asset
Having already the asset activeSceneAsset you can use AssetDatabase.TryGetGUIDAndLocalFileIdentifier in order to optain the GUID we need in the last step:
if (AssetDatabase.TryGetGUIDAndLocalFileIdentifier(activeSceneAsset, out var guid, out var file))
{
// TODO see below
}
and now having that guid we can use it in order to
Get the AssetReference via the GUID
The reason why we wanted to get the GUID is because we can now use it for the AssetReference constructor taking the GUID as parameter:
var activeSceneReference = new AssetReference(guid);
NOTE: All this is ofcourse only possible in the Unity Editor itself since AssetDataBase does not exist outside of it.

URL updated for GeoAnchors in RealityKit with anchor info after being removed from ARView

I'm using GeoTrackingExample project from Apple:
GeoTrackingExample
and there is a bug in the logic where after you reset the AR Session, it still retains the anchor information in the URL. So the steps are as follows:
start app
tap in the arview and place an object
select Reset AR Session from the menu
tap in the arview to place an object
select save anchor from the menu
save file to device
Reset AR Session
Load the saved file
When the file loads, it will load both the initial object placed in the AR view in step 2 then removed in step 3 and the added object that was placed in step 4. It should only have saved the object added in step 4, not both objects from step 2 and 4. When stepping though the code to debug, it appears that the the anchors are removed from the ARview but somehow the URL will contain the path for both the anchors. What else do I need to do to clear so that objects from previous sessions are not added to the URL in the current session? Is the URL modified when the object is added to an ARView? Please help! Thanks
The example code from Apple uses a computed var to store the array of placed Geoanchors in the scene but since the computed variable is read-only, the values in the array cannot be removed when the scene is reset so it was keeping a long list every time a model was added to the scene with no way to delete them (that I know of.) Fixed the issue by not using a computed variable and modifying the code accordingly:
var currentAnchors: [ARAnchor] = [] // from
var currentAnchors: [ARAnchor] {
return arView.session.currentFrame?.anchors ?? []}
append the geo anchor to the array when the anchor is placed in the scene
add currentAnchors.removeAll() in the reset AR session function
Not sure if this is helpful at all to anyone out there but I'm glad I figured it out!
** Anyone know why they used computed variable for storing AR Anchors?

Using LSO (Local Shared Objects) within iOS Development and Calling File Back Up

I am developing a app for iOS using Flash, and I've created a LSO using the following code:
var so:SharedObject = SharedObject.getLocal("name");
so.data.user = enternamehere.text;
var result:String = so.flush();
I'm using a input text field so that users can enter their name. The instance name is "enternamehere".
I'd like to be able to call the information stored from the input text to appear on a different scene within the file.
So, a user enters their name on scene 3, and it appears on Scene 4 and the name is stored locally.
Any way of doing this?
Thanks

UIWebView loading a local image that gets overwritten but it doesn't refresh

My problem is this
I'm loading an html string into an UIWebView, in which i'm referencing a local image from my application's Documents folder.
<html><body><img src="image.png"/></body></html>
It loads just fine, no problems with the baseUrl or anything. The problem is when I do some stuff and generate a new image, with the same name, and save it in the same Documents folder, overwriting the old one (I delete the old one if it exists and save the new one).
Now, with the UIWebView still loaded on the screen, if I do a [webview reload] or manually load the html string again, I still get the old image, the one I have just overwritten.
I already checked in the simulator folder, the image.png there is indeed the new image, not the old one. And I already did everything imaginable to stop the webview from caching.
Of course, if I save the new image with a different name, say "image2.png", and reload the html string with src="image2.png", it all shows up ok.
What am I missing here?
Try appending a random query string to your image source.
ie.
function ImageSource(src){
return src + "?time=" + (new Date()).getTime().toString();
}
function ForceImageReloads(){
var images = document.getElementsByTagName("img");
for (var i=0;i<images.length;i++){
var img = images[i];
var s = img.getAttribute("src");
img.src = ImageSource(s);
}
}
ForceImageReloads();
Or something similar to that :)
This maybe a problem with the simulator. I had something similar once. Try running your code on a real device. For me, the simulator seem like it is lazy to reload data that have the same name.

How to delete a file while the application is running

I have developed a C# application, in the application the users choose a photo for each record. However the user should also be able to change the pre-selected photo with a newer one. When the user changes the photo the application first deletes the old photo from the application directory then copies the new photo, but when it does that the application gives an exception because the file is used by the application so it cannot be deleted while the application is running. Does any one have a clue how to sort this out? I appreciate your help
This is the exception
The process cannot access the file
'D:\My
Projects\Hawkar'sProject\Software\Application\bin\Debug\Photos\John
Smith.png' because it is being used by
another process.
//defining a string where contains the file source path
string fileSource = Open.FileName;
//defining a string where it contains the file name
string fileName = personNameTextBox.Text + ".png" ;
//defining a string which specifies the directory of the destination file
string fileDest = dir + #"\Photos\" + fileName;
if (File.Exists(fileDest))
{
File.Delete(fileDest);
//this is a picturebox for showing the images
pbxPersonal.Image = Image.FromFile(dir + #"\Photos\" + "No Image.gif");
File.Copy(fileSource, fileDest);
}
else
{
File.Copy(fileSource, fileDest);
}
imageIDTextBox.Text = fileDest;
First of all, you code is not good.
The new image is only copied if there is currently no image (else).
But if there is an old image, you only delete this image, but never copy the newer one (if).
The code should better look like this:
if (File.Exists(fileDest))
{
File.Delete(fileDest);
}
File.Copy(fileSource, fileDest);
imageIDTextBox.Text = fileDest;
This code should work, but if you are getting an exception that the file is already in use, you should check "where" you use the file. Perhaps you are reading the file at program start. Check all parts of your program you are accessing these user files if there are some handles open.
Thanks a lot for your help and sorry for the mistake in the code I just saw it, my original code is just like as you have written but I don't know maybe when I posted accidentally I've put like this. when the application runs there is a picturebox which the image of each record is shown, that is why the application is giving an exception when I want to change the picture because it has been used once by the picturebox , however I've also tried to load another picture to the picture box before deleting the original one but still the same. I've modified the above could if you want to examine it