Persistent Store data lost after session terminates in Blackberry application - blackberry

I am using persistent stores to store data in a Blackberry application.
While I create objects and store it in persistent store in same session data is saved properly.
But the data is not recovered from store in next session.
How do I fix this?
My code is as follows:
static TrialStore ts = new TrialStore();
static Vector data= new Vector();
synchronized (store) {
store.setContents(data);
ts = new TrialStore();
ts .setElement(TrialStore.USERNAME, username);
ts .setElement(TrialStore.PASSWORD, password);
data.addElement(ts);
store.commit();
}

You need to use the PersistentStore class to get and store the persistable object, for example:
Vector data = (Vector) PersistentStore.getPersistentObject(KEY).getContents();
Once you have updated the data, you can store it using:
PersistentStore.getPersistentObject(KEY).setContents(data);
PersistentStore.getPersistentObject(KEY).commit();

Related

IndexedDB with ngforage

I am storing data on the browser indexedDB and I am using Angular 14 with ngforage to store the data inside the indexed DB. So I want to be able to catch an error if the indexedDB memory is exhausted. So when I catch the error I am getting an empty object back as an error. How can I get an actual error when the memory is full so that I know what to if the storage is full?
Below is my code for storing the data inside the indexedDB:
this.obj.id = uuidv4()
this.obj.name = this.name.nativeElement.value
this.obj.surname = this.surname.nativeElement.value
this.obj.age = this.age.nativeElement.value
await this.setItem(this.obj.id, this.obj).catch((reason)=>
{console.log(JSON.stringify(reason))});

How to resolve with a exception "Cannot start to manage an object with a realm when it's already managed by another realm"

I'm using Realm Mobile Database in my Xamarin project. And I had a problem when used to realm.Add(obj, update) statement. It throw a exception "Cannot start to manage an object with a realm when it's already managed by another realm". What I didn't see on Swift version on same a demo. I knew when realm object's IsManage is true, and I added a object exist in realm to a another object for update then throw that exception, so how I can update a realm object with a member what exist before that.
var objUpdate = new AccountAccessDB()
{
Id = this.Id, //Id is PrimaryKey
User = this.User // this object existed
};
objUpdate.something.Add(new Object()) // this is that I want to update.
realm.Write(() => {
realm.Add(objUpdate, true);
});
Thanks!
It looks like you're opening to different realms and then try to add an object from one realm to the other realm.
Remember that realm is unique by it's configuration, so if you pass a configuration when opening a realm, you have to use an identical configuration when trying to open the same realm.
// First time you open realm
var realm = Realm.GetInstance("my.realm");
...
// Somewhere else in your code
var realm = Realm.GetInstance(); // <== This is not the same realm!
var myRealm = Realm.GetInstance("my.realm"); // <== This is the same realm
I recently came across the same issue and managed to find the issue.
In my case, I was importing a large amount of unmanaged objects to Realm.
Some of these objects had a property pointing to a custom User object, which I was naively assigning in the object's constructor.
Naturally this means that I was trying to import unmanaged objects that had a property which was pointing to a managed object (created in a different instance, too).

iOS Swift Realm Sync Issue

I used this configuration code for local storage.
var configuration = Realm.Configuration.defaultConfiguration
configuration.encryptionKey = getKey() as Data
I used this configuration code for sync with server.
let syncServerURL = URL(string: serverUrl + objectName!)!
var configuration = Realm.Configuration.defaultConfiguration
configuration.encryptionKey = getKey() as Data configuration.syncConfiguration = SyncConfiguration(user: SyncUser.current!, realmURL: syncServerURL)
I create some data without sync, it is saved locally. However, if I turn on sync(different configuration), the previously created data(locally) is not synced to the server? How to sync already saved data?
Realms are uniquely referenced by one of three mutually exclusive Realm.Configuration properties:
fileURL
inMemoryIdentifier
syncConfiguration
Realm configurations with any of these properties with different values will refer to separate Realms.
So your initial Realm has a fileURL value (with nil for the other two properties), whereas your second Realm has a syncConfiguration value (with nil for the other two properties) so they refer to separate Realms.
If you wish to copy data from the first (local) Realm to the second (synced) Realm, you may do so using Realm's APIs for reading objects & creating objects just like you would for any other data.

iOS app saved data lost after updating

I have an iPhone app that I developed with Xamarin and am publishing on HockeyApp. Whenever I put a new version of the app on HockeyApp and someone updates their current installation on their phone, they lose the saved data. Is there any way to prevent this?
EDIT
I have an entitlement that let's me share the data with my widget too. Could that be the problem? This is how I'm writing/reading the data:
this.nsUserDefaults = new NSUserDefaults("myGroupId", NSUserDefaultsType.SuiteName);
// Write data:
this.nsUserDefaults.SetString("myValue", "myKey");
this.nsUserDefaults.Synchronize();
// Read data:
string myValue = this.nsUserDefaults.StringForKey("myKey");
EDIT
After changing the above code to the following, it now persists saved data after updating:
// Write data:
NSUserDefaults.StandardUserDefaults.SetString("myValue", "myKey");
NSUserDefaults.StandardUserDefaults.Synchronize();
// Read data:
string myValue = NSUserDefaults.StandardUserDefaults.StringForKey("myKey");
But now I won't be able to share data with my widget...how can I solve this while still being able to share the data with my widget?
If you try to read the data before calling this.nsUserDefaults.Synchronize();, you won't get the data.
So if you do:
this.nsUserDefaults = new NSUserDefaults("myGroupId", NSUserDefaultsType.SuiteName);
// Read data:
string myValue = this.nsUserDefaults.StringForKey("myKey");
You won't get the data. But if you call the Synchronize() method before the read you will get the data:
this.nsUserDefaults = new NSUserDefaults("myGroupId", NSUserDefaultsType.SuiteName);
this.nsUserDefaults.Synchronize();
// Read data:
string myValue = this.nsUserDefaults.StringForKey("myKey");

How to pass Core Data objectID and use it with Continuity

Just trying to update some Core Data apps with Continuity and have run into a bit of an issue with using the selected objects ID in the userInfo dictionary to display the correct data on the continuing device.
My first thought was to use the ObjectID, however on the receiving device this would never find a corresponding object in the Core Data store.
As it turns out the URL representation of the objectID contains the UUID of the store itself, and because the two stores UUID's are different this is obviously going to fail.
So I guess I could replace the Core Data store's UUID in the URL with the continuing devices UUID and use this, and no doubt it would work.
The Url seems to be of the following format
Does anyone know what the correct way would be to pass a reference to an object between two devices with core data stores that are synchronised via iCloud?
I'll answer this one myself and see if there are any better answers...
I pass the url of the objectID (from objectID.URIRepresentation) using Continuity API and on the receiving device create a new URL using the following:
url is the url passed in the NSUserActivity.userInfo dictionary
let storeUUID = self.identifierForStore()
// Switch the host component to be the local storeUUID
let newURL = NSURL(scheme: url.scheme!, host: storeUUID, path: url.path!)
func identifierForStore()->NSString? {
if let store = self.persistentStoreCoordinator?.persistentStores[0] as? NSPersistentStore {
return store.identifier
} else {
return nil
}
}
This seems to work just fine - hope it helps someone

Resources