I've watched the Coursera android course and I have doubts how Android works in my application that I'm building. It does basic stuff, like register and show my info and do TODO using server as database. And I know it depends how I want to it begin built. Need some options.
Fragments can be built in ActionBar and whenever I want be called? Or is it bad to this way and stick with default menu built and hide it programmatically? Tried to google and didn't find any information.
The MainActivity is made to make http request POST to register name, email and password in my server. Is it possible to start the SecondActivity whenever he logged in? It's just like Instagram. But, I could set a condition to check depends if logged or not change the setContent(R.layout.main) or setContent(R.layout.second)?
When the register is done. All the data is saved on the server. But I want to check every time he changes activity or do some action if he's logged in or not. Could I use some thread with a flag(bool)? Could be a bad practice and reduce the performance? Or SharedPrefrences adding flag(bool)? But SharedPreferences are saved after the application is closed?
About to show my information in every Activity, like name, age and sex etc and such. Making request http just to show information is quite bad for my application, since it's just TODO app and I don't need to be connected to internet to see my info, but in case of edit, yes. So if I save in the SharedPreferences, but stays the same doubt, it will save after I close the application?
Since your question is likely to be drastically edited (as i advised in a comment) i quote the original text here.
Fragments can be built in ActionBar and whenever I want be called? Or
is it bad to this way and stick with default menu built and hide it
programmatically? Tried to google and didn't find any information.
Yes, fragments can be used whereever you like. But thats not really an answer.
Base your design on the various activities (think "what app screens should users navigate", and give these one fragment each.
The MainActivity is made to make http request POST to register name,
email and password in my server. Is it possible to start the
SecondActivity whenever he logged in? It's just like Instagram. But, I
could set a condition to check depends if logged or not change the
setContent(R.layout.main) or setContent(R.layout.second)?
Yes, you could have a LoginActivity that is called with startActivityForResult(). It would connect and return the success/failure. (See http://developer.android.com/training/basics/intents/result.html )
Also, keep in mind that HTTP POST is not encrypted, the password is sent as plain text.
When the register is done. All the data is saved on the server. But I
want to check every time he changes activity or do some action if he's
logged in or not. Could I use some thread with a flag(bool)? Could be
a bad practice and reduce the performance? Or SharedPrefrences adding
flag(bool)? But SharedPreferences are saved after the application is
closed?
Yes, SharedPreferences are stored after exiting the application. Ideal to simply implement app settings, but when storing lists of items you should look into other solutions. A JSON file may be of use, you could directly pull/push it from/to server.
About to show my information in every Activity, like name, age and sex
etc and such. Making request http is quite bad for my application,
since it's just TODO app and I don't need to be connected to internet
to see my info, but in case of edit, yes. So I saved in the
SharedPreferences, but stays the same doubt, it will save after I close the application?
See answer above. In short get a JSON string from the server, store it locally in a file. View and edit the local file, then upload it whenever you want. This way it works offline too, but can still download/upload the changes.
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.
For example I expect this kind of situation: data in my application lost relevance and so it usless until update. And until update it have to show users some predefined message.
Is here any simple and free solution to this task?
Guess I can use some server to somehow send simple messages... but it sounds way too complicated.
If this is important I use Xamarin.
Update: main difficulty here is fact - my application can't in any way define if it's outdated or not. This may happen in random moment.
Although the requirement is not very clear I assume Update here means app update.
each time user launches app make call to an api on ur server to check if user needs to update app
If that returns true take user to a static view that says app needs update and redirects user to google play to install updates
If you want to avoid using a server, you should try Firebase (https://firebase.google.com/). More specifically, you should use Firebase Remote Config (https://firebase.google.com/features/remote-config/).
Define in a key-value pair of something like minimum_app_version_required in Firebase Remote Config. Every time user opens the your app, compare the values of app version and minimum_app_version_required that you are getting from Firebase console and show a dialog box accordingly. You can also change the value of minimum_app_version_required anytime you want.
Just set some internal flag. That when that situation occurs, you can set the flag to true and just edit whatever layout element you are using such as listView or any other element with your predefined messages saved in strings.xml. You can also build any custom pop up screen, depends how you want to show them. Let me know if you didn't understand or exactly how you want?
Need to implement versioning for this problem. To achieve this, you have to maintain a version number in server, this is the version number you app will have to save and use it to validate with server. If both are not same, then app will get the latest data from the server.
I want to implement a feature in an app where users can add friends and check and compare each other stats from the java objects created, which involves a few subclasses.
I was wondering if anyone know what the best way to approach this would be?
The only thing that pops out is using Firebase. Where the user would click a button to upload the data to Firebase with a UUID link, and then give the UUID to the other user, where he/she would have to manually type the UUID in a textfield, and it gets the data from Firebase.
Would method be viable and is there any other better options?
Thanks
I would probably create a file (you can invent any ending) with all info you need displayed in json. That file can be shared via Whatsapp or what ever and imported in your app?
But I don't know what "stats" that are that the users can compare but I think they will change from time to time? So I would guess an online service would be better because otherwise to update, they have to share again and again?
I am working on application, my requirements is when i post data as parameters like ID, Value etc using rest webservice and than i get some data as a response like deviceID, VendorID, driverID.
MY application senerio is. when user first time install app he/she can see the screen that enter the above data like ID, Value etc and some response appears that response is basically user configuration like deviceID, VendorID, driverID and has to save. And and than automatically move to the next screen using intent.
Now when user close app and than again open he/she will automatically move to list screen if he/she is login other wise stay on login. NO configuration screen at the, because its setting first time save in app (deviceID, VendorID, driverID).
How to save that configuration data of user first, which one is the best way.
Please give me best solution like in tutorial form and also little bit explenation.
Thanks
It depends a lot on what the "some response" is and how much data do you want to store.
In Android Storage Options:
http://developer.android.com/guide/topics/data/data-storage.html
There's Shared Preferences:
http://developer.android.com/reference/android/content/SharedPreferences.html
http://www.vogella.com/tutorials/AndroidFileBasedPersistence/article.html
How to use SharedPreferences in Android to store, fetch and edit values
Maintaining a database seems to be an optimal way.
You can store, update or over-write the data according to your need. The Id's can be maintained in tables, and further info with each Id can be associated in rows, increasing attributes and relating it with keys.
http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html
http://www.vogella.com/tutorials/AndroidSQLite/article.html
http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/
I'm here today asking someone if they know a way to make a set up screen on first start up.
Here's the scenario: When someone downloads my app and uses it for the first time, it has to show a method where users make a password. On subsequent uses, I don't want it to be shown anymore. Does anybody know how to do this?
You can use the SharedPreferences for this purpose.
At the start of your application, check if the key "myKey+versioncode" is present or not in the SharedPreferences. If it not stored, then it means your application has not bee started yet, let the user create his/her password. Once the password is created, add the SharedPreferences "myKey+versioncode" with any value you like, and next time you will find this SharedPreferences, so it means the user already started the application and created its password.
However be careful about the "versionning" of this key, you might also want to keep a single key instead of one per version of your application.
Edit: Concept found at the time I was looking for EULA inplementation, here: Simple EULA implementation for Android