File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Android and the fly likes Is there a Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "Is there a "refresh" ability on an activity?" Watch "Is there a "refresh" ability on an activity?" New topic

Is there a "refresh" ability on an activity?

James Elsey
Ranch Hand

Joined: Dec 21, 2007
Posts: 228

I have an activity, inside the onCreate() method it pulls some data from another class

That data might change, how can I refresh it? Do I need to call onCreate() somehow, or is there an easier way?

Kind Regards, James. OCPJP 1.6 || My SCJP / OCJCP Study Notes
Interested in : SCJP, Google App Engine, Stripes, Android;|| My Bite-Size SCJP Study Blog
Piyush Patel
Ranch Hand

Joined: Feb 24, 2009
Posts: 127


James Elsey : how can I refresh it? Do I need to call onCreate()

you can't call onCreate() method that is Andoird life cycle method. that is being managed by Android OS.

To get refreshed data from another class you can put the code inside onStart() method. that is being called after onCreate().

Go through Android Life Cycle

Thanks :-)

Monu Tripathi

Joined: Oct 12, 2008
Posts: 1369

Note that an Activity is created, started, resumed,paused, stopped or destroyed automatically by the system depending on events generated by user. There are callbacks with similar names that help you setup your activity and do what you wish to do across activity life cycle.
What you are referring to is refreshing your data set/data store. There is a subtle difference between the two.

You can refresh your data set any time you wish(by calling appropriate method on your data store instance). And if you do it inside correct Activity life cycle method, your users will see updated data every time.

For e.g.: onResume() is called whenever an Activity is brought to the front. So, if you refresh your data set in onResume() the user will see updated view every time.

[List of FAQs] | [Android FAQ] | [Samuh Varta]
I agree. Here's the link:
subject: Is there a "refresh" ability on an activity?
It's not a secret anymore!