The wonderful use of fragment in Android that you may not know
This article mainly introduces the relevant content about the wonderful use of fragment in Android that you may not know. Share it for your reference and study. Let's have a look together.
Let's take a look at the renderings first
In software development, the login function is very common and important. Take this as an example to illustrate a usage of fragment to make development more comfortable
1. The reason and meaning of this usage
2. Look at the usage first
Call a static method we wrote in utils anywhere we need to log in
Write it once and call it easily from now on
3. Implementation mode
2. First define a fragment to handle callback
1. Implementation of callback
2. The context passed in should be a subclass of fragmentactivity
In practice
Appcomatactivity fragment. Getactivity () meets this requirement
3. First add the frame to the activity
4. Get callback according to onactivityresult of fragment
Source code download:
github: https://github.com/While1true/---Fragment-
Local download: http://xiazai.jb51.net/201707/yuanma/Fragment--master (jb51.net).rar
4. Summary
Using the same life cycle of fragment and activity, many things can be done in the same way, such as applying for permission
Well, the above is the whole content of this article. I hope the content of this article can bring some help to your study or work. If you have any questions, you can leave a message. Thank you for your support for programming tips.