简体   繁体   中英

How to call a method in a Fragment when the Activities onResume is called? (FragmentPagerAdapter)

I made an activity with a FragmentPagerAdapter and some Tabs.

When onResume is called (The user exits the application and enters it again) I want to update the Fragment. (Connecting to a Web Server)

My problem is when I override onResume in the Fragment it is also called when the User switches a Tab. I don't want that!

What can I do?

Have you tried other events like "onCreate" and "onStart"?

Another option would be to save a timestamp after getting data from webserver, so every time onResume is fired you check this timestamp to determine if your data needs to be refreshed.

You can do it using:

long timestamp = System.currentTimeMillis();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM