Does Shared preferences get shared across user - android

I am having some question, kindly help me out, following are my questions?
Does shared preferences data get shared across users?
Also can we have same widget IDs in two different users?
I am having a widget which any user can use. I am getting some
conflicts when a guest user or a any new user is switched to. Specifically, my widget is resizeable and in order to save its state so that it can be inflated accordingly on phone restart or some refresh events. These are working perfectly for the Admin User but it behaves abnormally when a guest is added or if the user is switched.

Yes shared preferences data get shared across users if we define CONTEXT MODE while creating SahredPreference for more detail you can read here for detail, and here. For widget id i think we can give same id in different users but here (i am not sure) also should be concept of Mode.

Related

Firebase user preferences as android preferences/settings

I'm developing an Application using Firebase analytics, authentication and DB services.
I need to save some preferences and some settings, related to the user.
Most of them are managed in a "SettingsActivity" which is similar to the sample one provided by Android Studio, but with this configuration if the user changes the device, those preferences are lost.
The app should provide a customizable experience for each user. To achieve this I'd like my preferences to be saved on Firebase insted of in local Preferences.
How can I achieve this without have to change too much my app structure?
EDIT:
Here's an example:
The user download my App on first device (Dev-A), he sign up, then he goes to settings and set first setting from A to B, and second setting from A to D.
Then he decide to download my App on a second device (Dev-B), he log in, then he goes to settings.
On Dev-A, first setting is set to B and second setting is set to D.
On Dev-B, first setting is set to A and second setting is set to A.
You will need to store this information in Firebase Database.
Use the user'd UID you get from Firebase Auth in the Database to store the settings.
The data should be under '/users/{uid}'
This way, you will persist all user specific data across devices. (Since the same UID will be presented to same authentication account)
Check this link in Firebase documentation to set the database security
You should try this library:
A implementation of SharedPreferences which syncs with Firebase database to keep your SharedPreferences in sync between multiple devices of one user and/or to back them up for app re-installs!

How to add an information page?

I'm new in Android programming and I need some help.
I'm doing an app for my thesis and I need at the first access(installation) to have an information page(like Google Calendar when recently installed). And the user will be able to go on pressing on a "Next" button.
This "page" must be visible only if the application is removed and after a while reinstalled.
Can someone help me to handle this?
There are many ways to go about this. One of them would be to take advantage of the SharedPreferences in Android. Make a default value of false. When your app starts, check the value in the shared preference that you set. If it is false, show the information dialog and then set it to true. If the value is true, continue with application startup. SharedPreferences will be deleted when you uninstall the application, so your information dialog will be shown again if the user uninstalls and then re-installs your app.
Here are some examples of using SharedPreferences.
You need to store some kind of flag for this, for example you could use SharedPreferences and store a key called "firstLaunch" with a default value of true. At startup read the flag, show info if it's true, and set to false.
There is a library called Showcase View to visualize the most important functions of your app.
The ShowcaseView (SCV) library is designed to highlight and showcase specific parts of apps to the user with a distinctive and attractive overlay. This library is great for pointing out points of interest for users, gestures, or obscure but useful items.
You could use that to develop your information page.

one time activity using sqlite

I understand how to create a one time activity that saves to preferences to make the activity appear only once. But can someone show me how to save the "first open" screen to sqlite. I want to prevent users from clearing the data and seeing the screen again.
to clarify
I am looking at a password login tutorial and i want the users to register a password with the app but once the password is set, I want the registration screen removed for security purposes. Can someone please help.
Thanks
Using SQLite as your storage is not going to help.
Android will store your database under /data/data/your.package.name/databases/yourfilename and thus, when a user clears the data for an app, it will remove any databases, along with shared preferences too.

Is it possible to show screen only once when app starts up?

I want to be able to prompt the users to enter the details required for the app only when it starts up for the first time (not other times). These details will be held in a database on the phone.
Would it be better to check the database each time or put these details in a shared preference? Furthermore, is this type of activity even possible on Android?
Depends on the details really. If it is a large amount of information you might consider using a Database. For just basic identification information, SharedPreferences should be fine.
If you do use a Database, you might consider loading them into your Application object. This would depend on how frequently you use this information in your app.
To check for the first start of the app, a SharedPreference is generally used AFAIK.
Use SharedPreferences or Database depending on the data complexity and its need later on..
Store a Flag in SharedPreferences and set this when user enters the data.
Check that shared preferences flag while on your first activity and redirects accordingly(to Details/one time page) if required.
here even if a user manually deletes data using Settings > Manage app > your app > clear data, Your app will know to get the details then from user....

What is use of preference activity in android?

I have studied preference activity but I don't understand it. Can anybody tell me what is the use of preference activity? How does it differ from activity?
Thanks
PreferencesActivity is a way to easily create preference screens such as those in Android itself, just look under Settings. These can be used inside applications to easily save preferences to SharedPreferences and then easily access these from within your app.
See this page for more information on PreferenceActivity.
An example of a PreferenceActivity showing some preferences:
Use:
It gives a very easy way to create a standard looking settings screen for any application.
Why:
minimal coding is required
How it works:
it takes care of UI.The values are stored in SharedPreferences automatically by the PreferenceActivity and so its scope becomes app wide.
Sample Screen UI:
such settings screen, you can use it for your app where user want to change setting.
Its one stop to manage your Shared Preferences. Through this, you can provide a group of Settings to user for your app. Since it only deals with preferences, that's why its different from regular Activity. Read this for more info
PreferenceActivity supports the simple handling of preferences. It can show a set of preferences to the user.
An activity on the other hand is a single thing a user can do.
Checkout Section 13 at this link
It is usually used to create a settings screen for applications .The values are stored in SharedPreferences automatically as soon as user selects a preference setting. It frees the programmer from explicitly saving preference values.
PreferenceActivity is a class that allows you to implement an activity that realizes a hierarchical organization of choices. Most often it provides a good bases for building the settings activity in you application.

Categories

Resources