Android control interface refresh skills summary

Today, let's sort out how to control our data refresh in the project.

The interface to be refreshed can be controlled globally without broadcasting and event bus.

Let's take a look at the renderings:

Recently, in the process of writing the project, I feel that many states in the interface need to be synchronized after changing the details page or other places. It is still troublesome to control.

For example, in a list interface, after I operate on the details page, the list status needs to be changed after I come back. If I don't operate, I don't need to change after I come back. The general writing method is either to consider startactivityforresult(), or to operate the current list every time the interface reappears (onresume method). Startactivityforresult is acceptable, It's a bit unwise to refresh the current list every time the interface reappears. However, it is sometimes not very convenient to use startactivityforresult. For example, I have more layers of interface. I go to the fifth layer to refresh the first layer interface. At this time, we should consider other ways.

The control interface trick introduced here is to define a global static class to store various judgment conditions of each interface, and then use the onresume method of the life cycle to judge the conditions.

Here is the code of this static class in the demo:

Post simple codes for these interfaces:

MainActivity :

SecondActivity:

ThreeActivity:

It is convenient to use this method to control the global judgment conditions, but there are still some restrictions when using cached data or passing parameters. The rest depends on the situation.

Note that when exiting the application, call clearmomery () to free up memory.

You can also make adjustments according to your project needs or your own ideas. Here is just a brief introduction.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>