I would like my main activity to load a loading message. Once this is displayed i would like to start my tab activity which has to load a fairly heavy RSS feed. Problem is i have tried overriding onStart and onWindowFocusChanged if hasFocus but neither draw the view before starting the other activity.
Anyone know how to do this? All the splash screen examples use a timer which is not what i want to do, i want it to stay while the data is loading and clear itself when the onPause is fired.
You cannot start another activity while you're still showing another one. You have to change you control flow.
Load you RSS feed with an AsyncTask while you're still in your main activity showing the loading message. When you finished loading all the data you need, store it somewhere, then start you tab activity. So you tab activity don't need to load the data itself but can fetch it from the place you stored it.
Related
I have 2 Activities.
First one is a list view and when i choose one, detail information Activity is opened.
Second one requires complicated loading process along with ViewPager.
The problem is that there are too many data to load & progress(includes Google Map data) and it makes my beginning animation's FPS terribly laggy, which is not good at all.
I decided to wait in the first Activity screen with central progress circle until second one is fully loaded.
How can I request Android to 'pre-parse' another Activity before being displayed?
I think the best way is after clicking on an item in the listview (first activity) start an asynctask to fetch your data. Then this task is complete, start your second activity passing a bundle with the data previouly fetched
I have an application which stores data in SQLite database. Main activity is just a screen with a single button. When user clicks this buton the second activity opens. The second activity is a list (ListActivity) which should contain all the records from database. Here is the question: which approaches fits better: 1) when button is clicked, start AsyncTask, in doInBackground method pull data from database and send pulled data to the second activity as a parcelable array or 2) start the second activity, in onCreate method pull the data from database and display progress bar while selecting data. I believe it is not based on primary opinion and there should be valuable pros and cons. But I am new to Android and I'm struggling to identify better approach for this. Thanks for your attention.
First approach is not user friendly. Because when user press a button to open different activity(In terms of UI), then user except to show a transition, Not the stuck in first activity. Actually it depend on your application UX design. Also first approach has another problem. If you load data in first activity then you have to transfer many data when you call another activity.
Use the slightly modified second approach. First start the second activity, then call the AsyncTask(in onCreate method) to load the data.
Well, I think the best is starting AsyncTask on clicking button and process data in doInBackground as You said. In onCreate() of second acivity display progress bar, and in doInBackground() send data and display items. It seems to be the best from point of performance.
I have a load activity which sets up my statics/singletons and does some async tasks.
Since Android can kill an app and then reload it without it's statics, I'd like to add a simple check if any of the values I'm grabbing are null, and redirect to the load activity if that occurs (and then return when complete). In this way, the user can return to what screen they were on when they left the app, but I can make sure I don't have any strange crashes.
What's the proper way to accomplish that activity redirect and then return? Do I use the back stack for that or is there a more correct technique?
It looks like a Fragment activity more than a Full activity, take a look at http://developer.android.com/guide/components/fragments.html, then you can implement the logic on view create inside the fragment manager.
I've got an app that uses ListActivity to give users a list of actions. When they click one I use an Intent to launch a separate activity.
My problem is that the actions that the app performs take about 20 seconds to finish, and since I don't want the user to receive that nasty ANR dialog, I tried to use AsyncTask to present them with a loading screen in the mean time. I tried using setContentView(R.layout.loading); on onPreExecute(), but it throws a NullPointerException which as far as I have figured out is due to the fact that loading.xml is not "a ListView whose ID is android.R.id.list".
So what can I do now? How can I show that loading screen? Is there a way around this pretty annoying situation? Any help would be greatly appreciated. Thanks!
I am not sure exactly what your use case is; you have a list of items that are populated immediately, and upon selecting one an action is taken? The action that is taken is to launch another Activity which performs background processing?
Or does it take that long to populate the list of actions?
If the former, you can use an AsyncTask for the long-running activity instead of an Intent to launch another Activity: in the callback you get for the click on the item in question, you would create the AsyncTask, and in doInBackground you would perform the long-running activity, with onPostExecute refreshing or manipulating your list as necessary.
Another thing to consider is using a dialog box to show a loading screen, if the loading is required to happen before you launch a new Activity.
If you can further describe your use case, I can help you more.
It's not the loading screen you need to have on the AsyncTask, it's that 20-second Activity initialization. I would look for a way to do all the setup in a background thread in a Service while the user is free to merrily bop around in other Activities. I'd try hard to find a way not to just stall the user for 20 seconds. Maybe take them to the target Activity and show them data cached from their last visit until the new set is ready.
Fire up and display your loading dialogs in your onCreate() of the Activity being called, then call Dialog.dismiss() in your AsyncTask's onPostExecute().
I have an app that contains a sequence of listviews, and those lists are populated with data retrieve from a webservice. I want to refresh this data when the user presses back to go to the previous list.
I have currently tried overriding the onWindowFocusChanged method, but this doesn't work, since when I start a webservice download, I bring up a progress dialog and close it upon completion. This causes a recursive effect (the dialog closes and gives focus back to the list activity).
Is there any way I can get when the activity is first shown? Similar to viewWillAppear for iOS?
Just override onResume() in the Activity. Just make sure to do whatever internet communication you do in a separate thread.