I’m a beginner to Android development. Something always confuses me. Let say if I want to create a simple app that shows all presidents of United States with some brief info, how do I store this information? Should I store these information in content provider while activity oncreate? Doesn’t it append the data everytime when user start this activity?
Should I store these information in content provider while activity oncreate?
You never store data in a content provider... a content provider is used in order to (guess what?), provide content. In most cases you won't need to create your own content provider; unless you want to share that data with other apps. If the information you are going to handle is going to be used by your app only, don't create content providers... just put your data in a database and access it from there.
Related
I am new to this site so I am sorry if there are any inaccuracies in this question. I am trying to create a login system using a local database. Previously I did some research on how to make a login system but still have no luck. I am using something like intent.putExtras() (sorry, not sure what the correct word for that is) to store user's details such as username, date of birth etc, so the following activity can receive the data from the previous activity. However, I just figured out that SharedPreferences is used by many people to implement a login system and I am planning on using it as I have an impression that it is more reliable (correct me if I am wrong). However, I have been implementing a login system using intent.putExtras() and never seen anyone implementing a login system that way. To make sure my current way of implementation is reliable, my question is, can I use intent.putExtras() instead of using SharedPreferences?
intent.putExtras(//something) only stores data in Bundle temporarily. You need to store the user info (or if user has logged in) somewhere, to be accessed next time you open the application.
intent.putExtras() are intended to be used, for example, when you want to pass data from one Activity to another.
Locally, sqlite and shared preferences are your only options.
My question is, can I use "intent.putExtras(//something)" instead of using SharedPreferences?
With what you want to achieve, no you can't.
After you edited your question:
If you only want to pass data then you can do so with intent.putExtras(), if you want to store data locally, then you will have to use sqlite or shared preferences.
I am stuck at a point and can't figure it out how can I manage to send user's data which is stored in the database to another user with admin privileges after user just press a button in an app and display this info on admin's screen.
Till now I am done with the database to store user info during registration, I am new to android development and have just basic knowledge is there any better way in which i can possibly do that please let me know.
thanks
Yes, I assume you access your SQLite with a content provider/resolvers. You have to make them available to other apps, at which point they can access your data. Starting reading about it here:
https://developer.android.com/guide/topics/providers/content-providers.html
Think about why you can easily use content provider/resolver to see all gallery photos, it works the same way. It is because the photos are stored in a publicly available SQLite database and by using content provider you can access or even modify them.
I have two applications and I want to be able to share a String value between them. For example: user changes the String in app A, when app B is launched, I want it to read the updated String (and vice versa).
I was trying to use SharedPreferences with Context.MODE_WORLD_WRITABLE, but it's been deprecated.
How can I achieve this?
EDIT: App A has to save the value without launching app B. App B has to be able to read that value without launching app A.
I looked at ContentProviders, but they look too complex, especially for a simple String sharing.
One option is use webserver for this. for example store value in web server from app1 and access this value from app2
option two is use content providers. Through the content provider, other apps can query or even modify the data (if the content provider allows it)
Simply put:
one application needs to send intent with data
the other one needs to listen for it with brodcast receiver.
Content provider is probably not the thing you are looking for.
here is good tutorial for brodcast receiver
Try http://developer.android.com/training/sharing/send.html or http://developer.android.com/guide/topics/providers/content-providers.html to share data between 2 applications
I have two apps and I want one app to change preferences in another app.
Is it possible? If so, then how?
It means that you need some passage between two applications.
If A application provides content provider, B application can access that content provider and change values in that provider.
Have a look this article http://developer.android.com/guide/topics/providers/content-providers.html
You could use Content Providers. Put your settings in a database so that the other application can read.
I have seen custom content providers for sqLite in apps, but thats about it. When should a Custom Content provider be built?
EboMike in this question says:
Other apps will be able to access your data.
You can wrap and abstract a lot of the query logic in your content provider, and limit access.
You will be able to lean on the system to allow for things like managed queries.
Remember that you can control user interacts with your data,for example you can prevent user from modifying data or you can force system to open data with explicit App and so on.