Trouble With TabActivity on Frequent Clicking The Tabs - android

In My application there are 3 tabs for Tab Host which contains activities .
These activities are downloading some images and videos from server.The problem
is when I frequently click the tabs I get force close due to many exceptions. If I solve one
another exception arise. so I want to introduce a progress dialog on tab click so that the user unable to click the other tabs.I tried including progress bar at the starting of onCreate() and onTabChanged() but its no use please help me regard this.
If this information is not eno

You will need to use AsyncTask to show progress bar.And for downloading use a Thread thus allowing the UI to load smoothly.
Check out this link for Progress bar with Async Task Progress Bar

Related

How correct restore state on MVP

I use MVP and it's work fine.
User click button on the View
show progress
call peresenter.download file
after success download file call view.hideProgress
OK. It's work fine.
But has one problem.
When user click button the progressbar is show. But if I change screen orienation then as result view is recreate and progress bar is hide. But operation was not finish yet. The operation is finish after 10 seconds.
So the question is:
How show progress bar (restore state) while file was not download success?
You can use Moxy library. It helps to save and restore state on configuration changes because it adds ViewState layer.
https://github.com/Arello-Mobile/Moxy
If you prefer native ways you can use loaders or retain fragments

Android: How do I get a circular progressbar replaced with a message if no internet connection?

I have a RecyclerView which is essentially endless, and it loads data 10 items at a time using a cursor. I got a circular progress bar to show up at the bottom when items are still loading, however, if I stop the internet connection, the progress bar continues to spin on forever. How would I implement a message that replaces the circular progress bar if there is no internet connection?
A good example of what I'm trying to do is what the Play Store uses, as well as reddit is fun.
(Progress bar while loading content)
("No internet connection" message to replace progress bar)
The code I used for my progress bar is very similar to the way #vilen implemented it here
You can change the ProgressBar layout with another layout that has both the ProgressBar and a LinearLayout with the icon, message and retry button. In onBindViewHolder, show only progress bar if there is internet connection, otherwise only show the LinearLayout. In your activity, when you detect a change of internet connection, call adapter.notifyItemChanged(adapter.getItemCount()-1) to update the last item.
You can see this answer for how to detect connectivity change.

Updating Custom listview item after on resume()

I have a custum listview with image, text, a download button and a progress bar for each item.
The plan is that when I click the download button, the progress bar which original is invisible becomes visible and starts to progress, while the download button changes to a cancel button.
But what happens now is that when I minimize the app to home and opens it back up, the listview refreshes(that is the adapter is called again) as the activity resumes. This undos all the states which have been set.
the progress bar becomes invisible and the download button shows up with the download icon instead of the cancel icon, even though the download continues in Asynctask.
What I need to do is to find a to set the state of the list item, such that the progress bar continues to progress and the button changes to cancel button. i.e to retain the ui state as the download goes on in the Asynctask, even when the listview is reinitialized.
I viewed` your question. The problem is regarding the Asynchronous AsyncTask that you used. I can try to explain you the problem and the recommended solution.
If you start the AsyncTask inside your activity, Now when you close the activity (finish) It is not guaranteed that the running AsyncTask also stop working and finish itself because of your activity is no longer running. That does not happen.
Another fact is that, As previously said that once you fire the AsyncTask you could not reuse it next time when you start the same activity again. In your case, it always starts the new AsyncTask when you open the activity.
Alternative Solution: You can use the Service component that can run in the background (keep in mind that it does not create the separate thread from your application, It's run on the application thread) means it has no UI and could be run even if your activity or application is not in front of the user. You can put your download logic inside it and bind with your running activity.
Regarding the state of the UI in adapter that you can manage by communicating between the activity and running service.
This is simple approach that you can use it.
Hope this will help!
Thanks
Bhavdip

Android indeterminate progress bar between activities

How to get an indeterminate progress bar between two activities, I mean, I'm in activity A, show the progress bar, while the progress bar is showing, a new activity B is started and in this activity B I want to close the progress bar. Thank you.
You can't do it that way. An Activity is what holds everything on the screen for your application. If you are "inbetween" two activities then you have no way to control what is on the screen.
You need to put the progress bar into ActivityB, and make it visible by default, then when you are done loading your data make it invisible with
progressBar.setVisibility(View.GONE);
If your ActivityB is taking a long time to load before showing any Views then it is an indication that you are doing some loading work on the Main thread, that you should isntead be doing in the background, and updating the Views once loading is complete.
There is no reason to do so. Starting a new activity is a very fast process, almost instant (unless you onPause method takes very long), so the progress bar will never be shown.
That being said, there is a hacky way to get a progress bar to be shown between activities
you call ProgressActivity(that you create) from ActivityA then after waiting for some time (delayed runnable) you call ActivityB. This does nothing constructive and should not be used.

Hide Progress Dialog from background-fragment

I'm encountering the following problem. I implemented a navigation with tabs and viewpager to swipe through my fragments. This is working fine so far.
But the fragments are all loading data via Async Task and for that they are showing an progress dialog. Which is self is also working as it should. My problem is, that because of the Viewpager not only the actual fragment is loaded but also the one next to it. So I see wrong progress dialog.
Is there any way, to achieve a behavior that the progress dialog stays visible for it's fragment (so, that the user is informed, when he moves to the next tab before the async task finished loading) but not anywhere else?
Hope it's clear, what I wanted to say.
Thanks for your help.
Best wishes
The progress dialog can be a "dialog" that hangs out in front of everything, or it can be a View that sits in place. So, my advice would be to make either a full screen (or just partial screen) layout that sits in your fragment and displays the progress dialog. It will move aside with the rest of the fragment if the user moves to a different fragment. If you set it at the top Z level, make it full screen and capture all taps to it (and swallow them so they don't cascade down into the layouts beneath in the z-order) I believe you'll have exactly what you're describing as your desired result.
The key is not to use ProgressDialog dynamically in code, but rather just the View version of it that you just place in your XML.
Edit:
I'm talking about one of these...
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>

Categories

Resources