Best way to start/maintain activity? - android

I'm trying to redesign my android app, but I'm not sure what the best programming method is for what I'm trying to do.
Currently, I have a page in my navigation drawer called "My Workout". In this page I have an expandable list view, and each item is a workout and contains 4 child items (Week 1 to week 4). When they click on a child item, a new activity is opened with 3 fragment tabs (Mon, Wed, Fri). Each tab contains a recycler view that is populated depending on the exp list view item clicked.
Id like to change it so the expandable list view activity is called "Choose a Workout", and the expandable list view is turned into a normal listview. When an item is clicked it goes to a new page(My Workout) in the navigation drawer and starts a new.. "activity" in the app. So instead of having the user have to go to each item, then the week, then the day, it'll simply load the first day(with the recycler view) on a new page. There will then be a button on that page saying "Completed", and when clicked, it will bring up the next day (Week 1 Wed), and it will continue that until the month is complete.
I'm pretty sure I can get this to work with simple intents and intent extras. The problem I am worried about is how will the app react when it is closed and re-opened to My Workout from the navigation drawer? As far as I know the intent will be lost because it is no longer coming from the listview page (Choose a Workout).
Does anyone know what the best way to save what workout they are on in the "My Workout" page, so if they start a specific workout, then close the app, then re-open it and go directly to the "My Workout" page, it is the same place they left off?
Thanks!

Best possible ways are using SharedPreference or SQLite. Saving the result in SharedPreference is always preferred. Save result into preference, once the user comes back to the app, check the result of the previously saved data/stage(whatever according to your app) and perform the action.

Related

Weird Shell page and ListView Navigation issue [Xamarin Forms]

I have a rather peculiar issue. My page has a list view with bunch of view cells containing appointment information. Now when user taps the list view entry they are redirected to appointment detail page using Shell.Current.GoToAsync(). On that page user can go back either through button press or through shell's back arrow.
Case 1.) When they press the Button "OK" - all works as intended, they go back to the page with listview, they can tap on any entry and it will open once.
Case 2.) When using back arrow, the page renders additional method run inside listview.itemtapped method, which I called OnListViewApptFinishedTapped. So every time the user goes back using the arrow, next time they press on any item from the list view, multiple appointment detail pages will open.
I hope I explained it well enough to get the gist of it. I have a temporary workaround with counter inside the ontap method, but it's definitely suboptimal.
Any pointers welcome!

Implement some functionality like in Instagram android app

There are two things which I like on the Instagram for Android app and I'd like to implement them in my app.
1. Infinite go back in history of fragments
If you tap on a user, you can see his details, taping on followers will return a list of followers, pressing on another user will show his details... and so on. Basically you can do this thing for many times BUT when you go back everything is instant without loading. How can this be implemented? My initial thought was to have only one activity with a top actionbar and for the rest use fragments (one fragment for user details, one fragment for users list) and so on. The problem is I can't think of a good way to allow going back in history. The only way I can see is by caching all the data (user data / list adapters) is an ArrayList so when the user presses back, take the last item from the list and instantiate the fragment. Is there a better way of doing it ? I'm thinking I could start a new activity for each user interaction and them when the user presses back, simply finish the current one. My only worry in this case would be running out of memory. Is there a way to cache fragments with their state ?
2.GridView inside ScrollView
On user details there are two main layouts: a layout with user details and a gridview of images. When the user scrolls, at the scroll's end, the gridview gets new set of items (load as you scroll). While I know how to implement load as I scroll for the gridview, I don't know how to add the gridview inside a scrollview and keep listening for scroll events
Haven't got a quick answer for number 2 but for the first question why not just add the fragments to the backstack with FragmentTransaction.addToBackStack ?
That way you get the natural back-action with fragments without having to start new activities for every action.

How to swipe to same Fragment but with other data:?

I'm building this application where I have 2 activities. Both of them consist of 3 fragment - one for title, one for content and one for tab control. It is shown at image below.
First activity serves for showing list of some data's headers (item name etc.), search, app info etc. When user presses item in list, app takes him to another activity to show him detail of chosen item. This "details" activity has 6 different content fragments and user switch between them via buttons in tab control fragment (I did switching between content fragments by showing chosen one and hiding all others - I don't know if it's right way, it's my firs app so it came to my mind at first :) ).
And what I would like to do is: When I'm in detail and I swipe left/right then I want app to take me to previous/next item's detail, to same fragment where I currently was in (so not to next content fragment, but to detail of next item in 1st activity's list).
Is this somehow possible please? Because I have totally no clue how to do it :)
And what I would like to do is: When I'm in detail and I swipe
left/rigt then I want app to take me to previous/next item's detail,
to same fragment where I currently was in (so not to next content
fragment, but to detail of next item in 1st activity's list).
If you want to swipe left-right then you would need a ViewPager widget. I'm not sure how should your details activity behave so I'm providing you with two options. Do you want to be able to switch to the next/previous item's details only when a certain fragment is the one currently viewed by the user(from the 6 content fragments, which I assume are related and show various data for a single item)? If yes then in that desired fragment you would replace the current content of the fragment(which will only act as a container) with a ViewPager and use nested fragments for the actual content. If the user switches to the details of a previous/next item's details and then suddenly wants to see the data for that item from one of the remaining 5 content fragments then you would need to have some updates method on them to refresh the data to show the current item(a OnPageChangeListener will be useful here).
Second option, is if you want to allow the user to swipe left/right from any of the 6 content fragments. If this is the case you would use the same method as above but you'll modify each of those 6 fragments.
Showing the next/previous item is easy, just get some sort of identifier of the data(a position, id), retrieve the whole used data(as in the first activity) and then cycle between it.

Should I use Activities or Views with tabs & lists?

I'm new to Java & Android development. I'm trying to develop an app that has 2 tabs, 1 tab has a listview inside of it. When you click on an item in the list, it takes you to another list.. and then you select another item, onto another list, ect.. until they reach the final page which I have setup as a non-selectable list. My question is.. should I create a new activity every time the user clicks on an item in the list? Or is that something normally done with changing views? If done with views, doesn't that pretty much disable their use of going back with the back button?
In the other tab I have an area with a list I guess in which you can remove items off of the list.. Now would I create a new activity for this and put this tab activity on every activity of the lists? I guess this part is what got me confused.. if I hadn't had the other tab my current setup of creating a new activity as the user drills down the lists worked just fine.
This all might sounds a little confusing but let me know if you guys need further explanation..
I would use changeable views only when the views are conceptually showing the same data from a different viewpoint. Since you say "it takes you to another list", I'd say use a separate activity.
As for the tab, my understanding is that you can model each tab as a separate activity, I'm not clear on why you would "put this tab activity on every activity of the lists"? Are you saying that one tab (the "remove" tab) is dependent on what's showing on the other tab ("the list tab")? Without knowing more about the context, but first instinct would be to use a separate "remove tab" activity and model the tab host as having separate activities per tab.

Android: ListActivity design - changing the content of the List Adapter

I would like to write a rather simple content application which displays a list of textual items (along with a small pic).
I have a standard menu in which each menu item represents a different category of textual items (news, sports, leisure etc.). Pressing a menu item will display a list of textual items of this category.
Now, having a separate ListActivity for each category seems like an overkill (or does it?..)
Naturally, it makes much more sense to use one ListActivity and replace the data of its adapter when each category is loaded.
My concern is when "back" is pressed. The adapter is loaded with items of the current category and now I need to display list of the previous category (and enable clicking on list items too...).
Since I have only one activity - I thought of backup and load mechanism in onPause() and onResume() functions as well as making some distinction whether these function are invoked as a result of a "new" event (menu item selected) or by a "back" press.
This seems very cumbersome for such a trivial usage... Am I missing something here?
Thanks, Rob
If the user hits the back button your Activity will likely get garbage collected.
If you properly start your activity from the menu with the different categories through an Intent, with passing the category etc. and then choosing the content in the onCreate method, you will get a new Instance of your Activity every time the user chooses a category, that will be destroyed after the user hits the back button.
This behaviour is perfectly fine. You don't have to cope with strange error cases and populating the list will take some time so the object creation time of the new ListActivity will be no problem. Try to program it as easy as possible for you and then test if there is a performance problem in the end of doing so.

Categories

Resources