Robert Lemiesz
Robert Lemiesz

Reputation: 1156

how do the onStart and onResume methods work in android

So im creating a texting UI for android. The way its handling message threads is that when i hit send it sends the message, creates a new message thread and then adds this message to the corresponing instance of my conversation view.

ConverseView is an activity that only has an onCreate(Bundle) method. This method creates an adapter and populates the adapter with values from a ArrayList. Array list gets a message added to it when the user hits send. However these do not show up in the views.

I believe that the problem is, the activity is being created then im adding a message, and the ListView is not updated. How can i fix this.

Upvotes: 0

Views: 833

Answers (2)

ahodder
ahodder

Reputation: 11439

Look here for more information on the lifecycle.

Essentially, onStart(Bundle state) is call after the Activity has started. This means that the activity is alive and responding to a) the application and b) to Android itself.

onResume(Bundle state) means that the activity is about to be displayed to the screen. This is where you should finialize any UI stuff you have to do.

As for your data not showing up, you need to call Adapter.notifyDataSetChanged() to push your adapter redrawing. Your adapter will not update (graphically) without this call.

Upvotes: 0

K_Anas
K_Anas

Reputation: 31466

Use a ArrayAdapter adapter; backed by an ArrayList. To update the data in the list after modifying your ArrayList just call adapter.notifyDataSetChanged().

Upvotes: 1

Related Questions