Android Creating a stored setting - android

I'm making a function in my android app that, at a home screen the user has the choice to view a league or choose a team. I want to know if its possible to and how to store their team selection so that it doesn't go to that activity the next time they start the app.
Also, how would I implement a menu button to change that team if they so wish?

SharedPreferences will allow you to store your league/team selection. You can retrieve this when you start your application and move to your next activity if it is set.
Look how to create Menu items in Android here. These are straight forward and very easy to implement. Just have that menu button launch your "select a team/league" activity

This should be something trivial that you should have been able to google:
For persisting simple data you can use SharedPreferences

Related

How can i switch main activity not in manifest?

I making android app. I have 3 activites:
first(main) activity which is empty and it's like navigation which ask you to add item.
Second activity which is needed for adding item's details and this activity have accept button which leads you to third activity.
Third activity have all data about item and from now on i want my app to make this activity main (default) activity with saving information about it in device memory.
I decided to make it without database because it should be really simple.
Can you help me with making 3rd acitivity main? Maybe there are some tricks.
not clear what you trying to ask. Like if user reached the 3rd activity, in the future if user open the app the app will automatically navigate them to the 3rd activity?
If that's the case, you could save this information in the shared preference, when the app start, the first activity check this value and navigate to the 3rd activity.
Recommend you use a single activity, use fragments for different pages, and use Navigation component to connect them. https://developer.android.com/guide/navigation/navigation-getting-started

Implement SearchView history without "searchable" declaration

I want to add search history to my SearchView. I found this question. It is rather useful but it looks like I can't handle it this way. First of all I use only fragments in my app while it looks like the solution above requires to create new activity for making search (well maybe I can reuse the same activity using some Intent flags). Also I can't provide search hint bia string resources.
I have fragment with SearchView in actionbar. When user enters search query I just perform web request and display results in the same fragment. I only need to add search history functionality to it. Can this be done completly programmatically?

Form application in android

I have a form application, in this application the user clicks on a Menu option(M1) to go to a form (Frm1). This is done using Intent.
The form (Frm1) have two buttons, a back button and a submit button. When the user clicks the submit button the form is submitted, when the back button is clicked the user reaches the menu option(done using Intent).
Now, When the user clicks the back button(he goes to M1) with a half filled form, he must be able to continue with the task when he returns back( to Frm1).
My logic was to collect all the values in the form to a bundle and carry it along the way from Frm1 to M1 and vice versa.
Is this a good approach, got any better idea?
Thanks in advance..!
If data entered in the form (Frm1) is used in your Menu Activity (M1), then obviously you should use bundles and send it between Activities.
Else it may be unwanted logic of working with forms data in Menu Activity.
Just imagine, that you will create new wonderful Activity before M1 in your app (dashboard or something similar to it). Now you have to pass your bundle to first activity, because else you will lose form's state, when user close Menu Activity. It's not good, anyway.
So, if you can encapsulate this logic in Form Activity, I recommend you to make it.
You can use SharedPreferences or Singleton storage. If your form's data is strings, numbers and flags - SharedPreferences is easy, good and safe solution.
Using a bundle is exactly the right way to do this, though if the user has pressed the back button, are you sure they want to keep the data they entered? You will have to provide some way to clear the form.
You can use either Bundle or SharedPreferences.
But better to go for SharedPreferences because Bundle is restricted to the session where as shared preferences is not.
Another option would be to save the form data in the SharedPreferences. The difference between saving it in a bundle and this is that the data will persist upon an app shutdown. Saving the data into a bundle will only last during the application's lifecycle

What is the way to navigate in Android app

I'm developing a Twitter client for Android and I would like to know which is the better way to build my app.
I want to have a listview that, when clicked, calls another listview to see details and so on but I would also like to be able to go back in my previous list.
What is the best way to do this in Android? At every click, I create a new intent associated with an activity and I do startActivity(intent) so that I can be able to go back with the Back button of Android.
Is it a good way or is there a better approach? I would like to navigate onward and backward of n-levels
The way to navigate back in Android is by launching the Activity intent waiting for a result Doc link and then when you need to go back from the new Activity simply finish it Doc link
Calling finish() in an Activity closes it and returns to the previous one. You can call in on a button click or similar.

Creating Favorites button in Android App(Need to pass object without changing Activity)

I am developing my first android app and need a little bit of help. I am creating a recipes page and I would like to have a Favorites button on it. I would like the user to be able to click the favorites button while they are viewing a recipe and have it added to the favorites page. However when the user clicks the button I would like them to be able to continue viewing that recipes page instead of moving to the favorites page.
I found out how to use intent to send data to another activity while changing the page. However I would not like the page to change.
I'm assuming I would be passing a button to the activity to do this(is there a better way?)
Thanks for all the help in advance!
You could collect all the favorites to a list and pass them all at once to the next activity when the user finally wants to switch the page. Or of course, you could simply make the list a public static member which the favorites can access, or - my preference here - save all the favorites with a 3rd party which can also handle permanent storage of it. That way you also isolate some dependencies: the recipes page doesn't and shouldn't need to care about who uses the favorites data and how. Likewise, I don't assume the favorites page is interested in when a favorite is pressed, but what favorites exist when it needs to show them.
You just need to persist the favorites list somewhere. Either in SharedPreferences or in a file, or in a database. On the button click add the item to the list. Your favorites activity then can use the list :)

Categories

Resources