TheLettuceMaster
TheLettuceMaster

Reputation: 15734

How to refresh listview by hitting back button - Android

I have a ListView that is dynamic and will constantly change. The user selects an item and goes to a different activity.

What I want: When they hit back button and return to the ListView, I would like to call a certain action to refresh ListView (in my case an AsyncTask).

I have figured out one way to do this: By adding my refreshing code in onResume. But I find it refreshes a little too much -- I only want it to refresh when coming from the forward activities.

Upvotes: 4

Views: 2971

Answers (1)

FoamyGuy
FoamyGuy

Reputation: 46846

I have figured out one way to do this: By adding my refreshing code in onResume. But I find it refreshes a little too much -- I only want it to refresh when coming from the forward activities.

put your "refresh" code inside of onStart() instead of onResume(). onStart() gets "Called when the activity is becoming visible to the user." - Activity Lifecycle

Which means that it will happen only at the time that you activity gets put onto the screen.

Upvotes: 3

Related Questions