How to abort a UI update process?

Inman

Well-Known Member
Licensed User
Longtime User
In my app, when the user clicks on an item in the Main activity, a new Content activity is loaded which displays the contents of the selected item. This content is populated using hundreds of labels in a scrollview, as a listview can't be used due to varying height per item.

Now imagine the user hits the back button when the labels are being added to the ScrollView. While the Content activity will close without any errors, the next time the user selects another item and loads the Content activity, it actually displays the leftover labels from the previous session (i.e the labels that couldn't be added in the previous instance as the user closed the activity with back button).

So my question is how to prevent this? Is there some command I can use in the Activity_Pause of Content activity to clear the UI update queue?
 

mc73

Well-Known Member
Licensed User
Longtime User
You can trap the back key button using the keyPress event, and include activity.finish there.
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
You can trap the back key button using the keyPress event, and include activity.finish there.

I thought when the user presses back button, something similar to Activity.Finish happens automatically. Doesn't it?
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
I think not. Check the logs, you'll most probably see the activity_resume sub triggered when returning to the activity, rather than activity_create, if you only hit 'back' earlier, without using activity.finish.
Check android's process life cycle post if haven't done so already.
 
Last edited:
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
I think not. Check the logs, you'll most probably see the activity_resume sub triggered when returning to the activity, rather than activity_create, if you only hit 'back' earlier, without using activity.finish.
Check android's process life cycle post if haven't done so already.

Sorry for the late reply. I had some health issues and was taking rest for a couple of months.

Anyway I tried what you said. What I noticed in the logs is that Activity_Create is always called, regardless of whether you called Activity.Finish for the same activity. So the issue still continues.

Any solution, guys?
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Back key does cause the same behaviour as Activity.Finish (as I recently found out).
I guess in Activity_Pause, you need to cancel the UI update and clear all the views.
To me it seems you have something still set in your Process_Globals that causes the remaining layout to load on Activity_Create.
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
I tried removing the main scrollview and its children views as well in Activity_Pause. But the issue still remains. In the log I can see messages such as
sending message to waiting queue (httpclient1_responsesuccess) and running waiting messages (1)

Process Globals contains only HttpClient1. I tried moving it to Globals but the result is still the same.
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
No I am not downloading any images. I use HttpClient to call an API that returns data in JSON format. Once the download is complete, I parse the data and then display them by adding close to 200 labels to a scrollview.

The problem occurs during this adding stage. If the user presses the back button while only say 50 labels have been added, the remaining 150 (or some of it) will get added the next time the same Acitivity is loaded.
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
Hmm. I thought the issue was at the point of adding the labels and not when downloading. I mean even if I use HttpUtils2 to download the data, the issue will be there when the user presses the back button during the UI updating time.
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
I understand. However I am using a modified Httputils service given here as I need to get the download progress value.

What I am about to say might be completely wrong as I know nothing about process queuing and messaging, so please forgive me. Since this issue is due to pending messages in the queue getting executed, will it be possible to clear the messaging queue of a particular activity, using the method mentioned below?

http://stackoverflow.com/questions/5883635/how-to-remove-all-callback-from-a-handler
 
Upvote 0
Top