How could i save the activity state and values after closing application and when i open it again it have the values of radio button and spinner and edit text
in android studio in kotlin or in java
You could save your data in SQLite database before closing your application and then retrieving again when the activity is started. Checkout this guide on how to use Room to save data. I also recommend you to read about other types of storage in this guide
You could use SharedPreferences.
SharedPreferences can be used as some sort of cache/cookie which will be useful when the user's detail/action is to be remembered when he comes back to use the application.
Android provides many ways of storing data of an application. One of this way is called Shared Preferences. Shared Preferences allow you to save and retrieve data in the form of key,value pair.
Related
I've been reading about Firebase Realtime Database for a while now I'm just wondering about the whole idea of event-driven data fetching from database. If data is downloaded from the database only when there was a change made to it, then it should be much less demanding on the device resources like battery or Internet connection. I thought I could remap the whole database fragment I need in my Android activity with my model objects that reflect the structure of my database and update its values with Child/Value listeners. Then I would have the whole data I need in a flexible form of POJOs and it would update every time there was a change in the database. So it is actually a real-time solution. But I wonder if such number of listeners would slow down or overload user's device in any terms like battery life or data transfer.
So, would It be a good solution to reflect database state in my Java model objects or should I go another way?
Could anyone resolve my doubts?
Thanks!
The listeners are triggered only when something is changed in the database. So you get data only when needed. It is expected that your app will lose their socket connections when there is no visible activity. That's the way the Firebase SDK works. Also, Android will aggressively pause background applications so they don't consume data and battery when the user isn't actively using it.
When you restart an activity for example, the Firebase SDK attempts to restore the websocket that it uses to communicate with the server. This websocket is fully managed by the SDK.
Hope it helps.
Firebase.addvalueeventlistener() only work when there is any change or update in database you are requesting. And it is a good way to move with JAVA objects or you can also use HashMaps<>.
As far as there is concern for device battery and performance then instead of requesting whole database you try to get only that part whose change event you wanna track.
And if you also want to have grabbing data on background as Whatsapp you can you Broadcast Receiver for internet and startservice() for where Firebase.addvalueeventListener() used.
I have an unity activity, which launches in another process than my App:
<activity
android:name=".UnityActivity"
android:process=":UnityKillsMe"/>
I save my SharedPreferences encrypted with this question (just in case this affects my problem and I have no idea).
Now if I want to edit a sharedPreference in process=":UnityKillsMe", the edits are not beeing accessable in mainProcess, it just takes the old version of the SharedPreferences. Not until I kill the mainProcess and launch the app again. If I do not kill the mainProcess, and edit the SharedPreferences, while they have been edited in process=":UnityKillsMe", the edits will be overwritten, and are lost.
How do I refresh SharedPreferences in the main process ?
The current implementation of SharedPreferences in Android is not process-safe.
From the docs:
Note: currently this class does not support use across multiple
processes. This will be added later.
The question is do you really need multiple processes in your application?
If you really do, i would suggest you to take a look at Tray, or consider some other form of persistent storage, such as a database.
Check out this answer also.
I am working on an App in android studio. The only thing is that if you close the app you need to start over with the game. Do you guys know how i can integrate a autosave option in my app that every time the user closes the app and start it up again that they don't need to start over?
onSavedInstanceState is used when recreating an activity due to things like orientation changes. check this link: http://developer.android.com/training/basics/activity-lifecycle/recreating.html
If the user is exiting the application completely then you should look into persisting the data with a sqlite db or using shared preferences during the activity lifecycle, check this link: http://www.herongyang.com/Android/Android-Application-Activity-Lifecycle.jpg
When the user starts the app again then check the persisted data during onCreate()
I need help to create an android application as I completely new to android.
I want to develop an application which will be able to perform database related operations on my android phone using that application.like it should allow user to see how many databases are there in my device.
when I select database,tables should display on my device and allow user to perform insert, delete, update operations. And also allow user to create new database.anybody is there to help me ? thanks .
Databases are application-specific in Android. One app can't touch the database of other app hence you cannot retrieve ALL the databases present in the system.(And i guess you shouldn't do that too) An android app can manipulate only its own database (There is something called as content-provider to use other app's database but other app should permit to do so).
Hence,you will not be able to create your desired application which you have mentioned.
user cant able to see database from device... so you have to get data from database programmatically and then inflate all data from database in to your application so that user can able to see the data which is resides in DATABASE
Hi guys I have been looking around for the answer to this but have come up with nothing, I would like to have an activity that asks the users for their details and then send them details to an external database after they first install the app. Does anyone have any suggestions on how to create an activity that will only be used when the app is launched for the 1st time. Cheers to anyone who can help
Save a flag in shared preferences that you set after completing the activity. You can actually save this flag anywhere, as long as you have it in some sort of persistent storage. Then on load, check in that activity if the flag exists (you can do this in onCreate), if it does, launch an intent to another activity.
Create a file or store a persistent property at the first boot.
Check for the existence of that file/property at every boot.