how to dislplay once my fragment when app install in android - android

I am new to this concept ,How to display my fragment after in application,that fragment only display at after installing my app, please any one suggest me how to do that

Basically you need to store a value outside of the application itself. Shared Preferences or a database (eg SQLite) or a file could be used. The former, Shared Preferences, would be the simplest. There are loads of tutorials and examples eg Android Shared preferences example
You could use a boolean type or even simply check for the existence of any type and then set or create it respectively.

Related

Multiple SharedPreferences

Actually, I have a doubt regarding SharedPreferences in android.
I have started learning Android a few days back and I am creating a SignUp Page for now, for that, I have searched the internet and got some ideas and now I am using multiple shared preferences in my code which I am thinking it would be a bad practice. So, I just wanna know, what happens to the Application if we create multiple shared preferences in the code.
This will just result in multiple SharedPrefenrences files (XML) in the data folder of your app. This is neither a problem nor a bad practice. If you have larger sets of structured data, consider using a database (e.g. SQLite/Room).
It is not bad practice at all. There is always a default shared preference.
we can get default shared pref filename using .getDefaultSharedPreferences() method.
you can get back up of any single shared pref file which is efficient.
With the concept of consuming more memory we shouldn't use SharedPreference to store large amounts of data, Alwayas use SQL DB in android for that. Multiple sharedpreference is good because , you can store data seperate for different sections within the app if it doesn't need to be shared. Shared preference is just a xml file with key value pair. So if you store only simple key value pairs, its okay to have multiple shared preferences. But be logical in your decision, dont just do that because you can

Save list content for next use properly

As you see on app like facebook, twitter, etc you have list of content in home page. if you close the app then open it again, you still have those content without load again from server.
currently i use this code to save all value in my app
SPref.setPref(getActivity(), Config.USER_ID, lb.userId);
SPref.setPref(getActivity(), Config.USER_NAME, lb.name);
SPref.setPref(getActivity(), Config.USER_EMAIL, lb.email);
its just save a string or a an int value not a list. i used saving data at local device with sqlite and a file for my other project. in this case in my new project, i want to make sure which way is better for saving list value.
by the way, i use SharedPreferences because someone told me its faster.
shared preference
is only to store KEY , VALUE pair, So you can store here small amount of data like username , some flags etc.
To store your normal contents like here you want to store list.
Use SQLite for this is the list will not frequently going to changed, or it will going to modify then use Cache.
Please follow this links for better understanding
https://developer.android.com/guide/topics/data/data-storage.html
https://developer.android.com/reference/android/util/LruCache.html
Shared Preferences certainly are very fast, but those aren't meant to be stored with a huge data set, As the name suggest those are meant to store the preference data of the app in a key value pair for example
setting the sound on/off
setting the logged in status
setting the day/night theme for the app.
In the above example whenever user changes a setting you can just store it in SP, and use it next time to make any decisions
For Larger data set, you have to use SQL lite
https://developer.android.com/training/basics/data-storage/databases.html
Or Realm DB(Third party library)
https://realm.io/

Android onSaveInstanceState for all instances of activity

After reading the documention it seems that onSaveInstanceStaate works per instance (as the name suggests). I am just wondering what the preffered method of storing data is so that it is available for all instances of that activity?
As MaciejGorski mentioned in his comment, there are different levels of data storage available in Android:
Shared preferences
Internal storage
External storage
SQLite database
Network
From personal experience, the lower you go down this list, the more complicated your implementation will become. Thus, if you are simply trying to save simple data for your app to be shared among different instances of an activity (or of multiple activities), shared preferences are certainly the way to go. You can even create private shared preferences, which only your app can access.
In any case, check out this SO answer for how to implement them: How to use SharedPreferences in Android to store, fetch and edit values

How to configure application settings in android?

In my application I have to keep some setting options for a user, like currency type, language, Calendar view (Either Calendar or List) etc.
Here I am confused whether I have to configure all this by creating database tables or should keep this in any xlm or text file. Please guide if there any more convenient way? thanks.
you can use android shared preferences to store a users preferences. Alternatively you can store "global" variables if you create a Application instance which has static or instance variables to access (but these values can be lost if your Activity is destroyed)
The answer on this thread has details on global application to store application wide variables
Hope that helps
Android has Shared Preference specifically for this purpose.
http://developer.android.com/reference/android/content/SharedPreferences.html
The solution would be to use shared preference
You can also look into PreferenceActivity which helps in building a setting page.

Store in sharedPreferences

I have some things in my app that I need to store, in order to have it available the next time I open the application. I wonder if I could save them using the sharedPreferences mechanism even if I don't have any "view" associated with them ! .If this is possible please let me know, if not, what would you suggest instead ?
All you need is a component that can furnish you a handle to the android.os.Context
An Activity is such a component. SharedPreference's data is stored in a file - somewhat akin to a properties file (key,value pair).
You can also create your own files and store it in the app's private directory.

Categories

Resources