In a recent project there were four fragments in one interface. Network requests are made in each shard.

The cycle also starts and loads. SetUserVisibleHint (Boolean isVisibleToUser) We can use this method to determine which shard is currently being displayed, true if the shard is being displayed in front of our eyes. This way we can do the network request in the same way. Next nonsense not to say directly on the code:

private long refreshTime = 0;  // Request time

	public void setUserVisibleHint(boolean isVisibleToUser) {
		if (isVisibleToUser && isVisible()) {
			if (refreshTime == 0|| (refreshTime ! =0 && (System.currentTimeMillis() - refreshTime) > 30 * 60 * 1000)) {
				if (isConnected) {
					initData();// Get data from the background}}}super.setUserVisibleHint(isVisibleToUser); }; . .// Network request method
	private void initData(a) {
		myProgressDialog.show();
		RequestParams params = new RequestParams();
		params.addBodyParameter("sessionId", sessionId);
		params.addBodyParameter("pageNo"."1");
		params.addBodyParameter("pageSize"."12");
		netUtil.getNetGetRequest(findHotUrl, params);
		// If the screen has been black for a while, it will also be loaded to make a network request.refreshTime = System.currentTimeMillis(); }... . .if (getUserVisibleHint()) {
			initData();  // When requesting a judgment
		}
Copy the code

There is a simple solution to the lazy loading problem. Hope to help everyone! (Growth history of Vegetable chicken ing)