I have stored data in Hive box but whenever i restart the app or kills the app during offline mode i.e when internet conmnection is not there, Data gets resets & shows null error.
await Hive.initFlutter();
Hive.registerAdapter<ProgressList>(ProgressListAdapter());
Hive.registerAdapter<VideoList>(VideoListAdapter());
Hive.registerAdapter<DashBoard>(DashBoardAdapter());
Hive.registerAdapter<CourseDetails>(CourseDetailsAdapter());
Hive.registerAdapter<AnnouncementsListData>(AnnouncementsListDataAdapter());
Hive.registerAdapter<VideoAssignments>(VideoAssignmentsAdapter());
Hive.registerAdapter<LessonDetail>(LessonDetailAdapter());
Hive.registerAdapter<CourseQuestions>(CourseQuestionsAdapter());
await Hive.openBox<ProgressList>("box");
await Hive.openBox<VideoList>("video_box");
await Hive.openBox<DashBoard>("dashboard_box");
await Hive.openBox<CourseDetails>("course_box");
await Hive.openBox<AnnouncementsListData>("announcement_box");
await Hive.openBox<VideoAssignments>("vfs_feedback_box");
await Hive.openBox<LessonDetail>("lesson_box");
await Hive.openBox<CourseQuestions>("questions_box");
await Hive.openBox("video_record_box");
If you're facing this in debug mode, then you probably don't notice the difference between debugging an app and using it in release mode.
Your app may be running fine, if you debug your app on an Android emulator as an example, make sure that whenever you close the emulator, and you want to open it again, make sure that the emulator doesn't clear all phone data whenever you open it again, so it looks like the Hive didn't save your data, but actually the emulator set that it will clean all phone data whenever it's launched.
How this is related to Hive:
The Hive package is a key-value database, which saves its data inside files inside your device, so clearing all phone data will normally clear those files.
You need to try your app in a real device for making sure that your data is saved, and I would recommend to test if first in a release mode version.
Related
I'm trying to save data using Hive while app running it's working fine but while app in background it's not work,
Btw all the data is primitive.
I try to save them using sharedpref but also I have got the same result.so what can I do now ?
I'm creating an Ionic react (TypeScript) app which uses the Community Bluetooth-le plugin.
When I try to connect to a device using requestDevice this shows the available devices and I can then pair/connect with that device and all is good.
await BleClient.initialize();
if (isAndroid) {
await BleClient.disconnect(devices.deviceId);
}
const device = await BleClient.requestDevice({
services: services ? services : [],
optionalServices: optionalServices ? optionalServices : [],
namePrefix: prefixFilter ? prefixFilter : "",
});
await BleClient.connect(device.deviceId, (deviceId) => onDisconnect(deviceId));
await BleClient.getServices(device.deviceId).then(
(services) => {
if (services[0]) {
//....
} else {
//....
}
}
)
However, if I save the device ID and then try to directly connect with that device using getDevices (rather than scanning and manually connecting) it always fails with the following console output:
Uncaught (in promise) Error: Device not found. Call "requestDevice", "requestLEScan" or "getDevices" first.
The code I use is this:
await BleClient.initialize();
if (isAndroid) {
await BleClient.disconnect(devices.deviceId);
}
await BleClient.getDevices(devices.deviceId);
await BleClient.connect(devices.deviceId, (deviceId) => onDisconnect(deviceId));
For clarification: I want to be able to search for available devices and connect to the device the first time the app is opened. Then, save the device ID and use this ID to connect to the device directly using getDevices from that point onwards. Likewise if the app is closed and re-opened I need to be able to take the stored device data and connect with that device directly without the whole scan and manual selection process.
I don't understand what I'm missing.
I assume Device-1 (app) is scanning and Device-2 is advertising. Try to bond the devices after first time connection. This allow you to connect it automatically without scanning next time.
Make sure the Device-2 is in connectable mode after getting disconnected from Device-1.
EDIT-1
For example I am using a generic app called nRF connect and a smart watch. In this app we can scan and connect with any BLE device. I am following below steps:
Scan
Connect
Bond (option available under 3 dots at top right corner, refer image)
After third step, device get bonded and later whenever the device is in vicinity you can connect with it, without advertising and scanning. PFA image.
This is the overview of process to be followed, in regards to code you can get many ready examples related to android or iOS. Hope this is helpful!!
I'm using Firebase+Ionic(AngularFire) to create a mobile iOs/Android app, and it works great. The only problem with using Firebase is that all the content in the app is being downloaded anew every time the user starts.
In an ideal world the app would save the Firebase-content to localStorage, and the next time the user starts the app, it would load from localStorage - and then simply "update" with Firebase to fetch the latest changes.
In other words we would load data locally and "resume" our Firebase-connection. Is this possible?
Note: Although we use AngularFire, the mobile app does not write data - it only reads from the Firebase.
On Android and iOS, Firebase supports disk persistence, which allows the cache to survive app restarts. This feature is currently not available for JavaScript environments, such as Ionic.
suppose i am playing a game on iphone, then press home button (multi-task) and update my game from app store. after update, i press the game icon to start again, will this game start from the very beginning (like a new-installed app) or just from where i was playing?
if it starts from the beginning, everything will be fine, but if it continues to play from where i was playing, it would cause trouble (still using old game settings : old AI, old score etc.)
thank you.
Your app will completely quit, the new app will be installed, and you will launch the updated app fresh.
But! While the code and assets of you app are updated, any stored data is kept. Anything in NSUserDefaults or files in the the apps documents directly, or (obviously) any data on remote servers, wont be reset.
Apps have to be ok with being shutdown anyway. Regardless of an app update or not, the app need to be able to start from scratch and be able to set itself back up however you want it to.
So save preferences, or other user generated data, in a place that won't be wiped and the updated app will read all that back in and you can use it to set the initial state of your app however you want.
I downloaded the source code located here on how to do a simple "To Do List":
http://www.icodeblog.com/2008/09/22/iphone-programming-tutorial-creating-a-todo-list-using-sqlite-part-4/
What I notice is when I add anything to the list and then re-ran the simulator... whatever I added is not saved.
I installed the app on my phone and notice that the database is reseted when the Phone is turned off. The app works fine... but when the Phone is turned off (hold power button for 5 seconds) and when it turns back on... whatever I added to the To Do list is gone. It's like it's just writing to the database temporarily.
I spent several days on this and can't figure it out why it keeps getting deleted after phone is turned off. Source Code is here:
http://staging.icodeblog.com/wp-content/uploads/2008/09/todo-part-41.zip
Probably you are calling the initializedatabase everytime you run the app. Then the app copies a new copy of the database so the default data is back. Try debugging, you should only run that method if the database isn't existing...