I am developing an application in android studio. The application allows users to create their account. I am able to allow users to sign up and log into their account by using shared preference.
In this application, there is a ListView that displays tasks added by the user. However, if a new user logs into the application, the data from the previous user who is logged out, is displayed in the ListView.
How can i handle the activities of the different users?
You should use database and crate a relation between users and tasks, to filter tasks added by logged user
You need to save these data in a database and add to each task a userId accordingly, then when you load these items query them and retrieve only the ones corresponding to the id of the user logged in
Related
I want to save some information about users' accounts in an EditText/TextView inside the app. For example I want my app to save in the EditText/TextView the content "Admin" for admin users and "User" for simple users. But I do not want to access the database every time the user opens the app. How can I save the content of the EditText/TextView even if the user decides to exit the app?
The users will not see the EditText/TextView. It will just help me avoid some reads in the database.
Just save it local / cache the data on the users device.
https://developer.android.com/training/data-storage/app-specific
I have an App in which I would like to start charging the user after they use a feature 5 times.
The unpaid App allows the user to click a button (to do a pre-determined task), and after that, the user must pay to be allowed to do the same task again.
I need to make sure that the log of button clicks is saved even when the user uninstalls/then re-installs the app - this is the main thing I do not know how to do.
Please kindly help!
first get the device unique ID with:
String id = Secure.getString(
getContext().getContentResolver(),
Secure.ANDROID_ID);
then store this id on your server with number of clicks, so every time the user redownloads your app you can identify the device and check how many times the user clicked the button
Well, if you want to keep this info even if the user reinstall the app, you can't save this info in local storage. You should have a database where you can store a user ID and how many times user has already clicked.
As creating a database and put it online requires some backend work, if you have no backend skills (like me), give it a try to firebase: https://firebase.google.com/
In short words, firebase is a Google solution to provide a backend to your app.
With firebase you'll be able to apply a login system (where you'll have a user ID) and create a dabatase (where you can store infos, like how many times user has used the feature)
I am developing a Firebase chat app.
I have implemented Firebase email/password authentication. So, when user signups successfully, I have a code through which on every signup/register the app stores user details like name,email, etc in Firebase database under uid node.
Then, the user searches for a friend using a email id,
if the uid with that email id is present in the firebase database, the function returns true,
then, the app, adds that email id under
<FirebaseApp>
<users>
....users details...
<friends>
<userid>
<unique pushed id> : searched email // here the friend's email id is added
After adding the new friend,
I am using a recyclerview to show the friend list.
So, the app retrieves all the nodes under friends>> current user's uid>>
As my database structure describes I have only saved friends uid in friends database.
At first step the user will have only friends' email ids. Let say in List friendsList.
Then I use this friendsList to retrieve all the other details of friends like profile picture, name, contact and etc... which is saved under users node.
But using for each loop retrieving the other details of every friend, and then store in a array list, then paasing that arrayList to adapter and then displaying to recyclerview. is a very time consuming process.
Becuase, it can have other functions too. like converting Base64 image to bitmap etc.
So every time activity starts , following all above steps, will make a lengthy process.
other that this, I have another way, where I can save friends other's details too under friends node. like name, contact etc. at a point when a new friend added to the database.
But again another question arises.
yes, I can store friend's other details too... But what if the friend updates his profile picture, contact?
So, this procedure is not suitable in my case.
How can I create a whatsapp like friends list in my Firebase app, where I every user's friends list will be always updated with his/her friends details.
also, the will not go under any lengthy process.
The best approach is to save all the necessary details in the friends node as well.
You can just save the Opposite_Friends tag in each user, where just add all the uids in whose friends list user is present, So that whenever user updates any detail, you can update it in every users Friends node as well.
I am developing a social network app that uses Parse.com as a back-end
I gave users the ability to change their name , email and profile picture (which is a parseFile)
And when users are logged in i gave them the ability to add posts
I add the posts by getting the user email and name by
ParseUser.getCurrentUser()
and saving the returned content to my ParseObject
but now the question is what if the user updated his data which is the profile picture or name or email how to update the post data dynamcly
You're going to have to write some cloud code. https://parse.com/docs/js/guide
I would create an beforeSave trigger for your users, check to see if the relevant fields are 'dirty' (have been changed), and, if they have been, create a new object of a customer class that just has a pointer to that user.
Save a pointer to the user on each post.
Create a background job that runs each day/hour/however often you want to do these updates that goes through all of your custom objects that contains a user, use Query.each() to go through each of those objects, and then do a query for all posts where the user key is equal to the user of the custom object. Then set the name/email fields as appropriate.
Make sure that when you're done, you delete all of the custom objects so that you don't continuously perform this job on more and more objects each time.
Alternatively, you could just add the user pointer to the post, and when you fetch your posts, include the user key, so that gets fetched as well. Then you can read the name/email directly from the user, which will always be dynamic. You have to make sure that your ACLs are set up so that users can't edit all of another user's info or something, though.
Just wondering how to do this on Android. My application needs to store a list of the user's accounts. Each account would have, account name username, password, server address etc.
I first tried to implement this with Preference Activity, this worked well but it seems to only result in a user interface for a single account. I am missing how to arrange this so the data is stored for an array of accounts, so if Account 3 is selected from a top level list the Preferences will display the settings for Account 3.
For example if you have an email app with multiple accounts, you want to be able to configure each account individually. They have the same settings, but different instances, so each account would have it's own preference file.
Thanks
You will most likely need a database (local sqlite usually) to store the data then you will have you use either the ListView and implement onClick methods OR as you say the PreferenceScreen and add preferences programmatically when you retrieve your data from the database for each account.
In order to achieve it take a look here
Dynamic ListPreference in android
or here
How can I keep on adding preferences when i click one?
hope this helps abit