I have the following code :
MainActivity.java
package com.erc.library;
import java.io.BufferedInputStream;
import java.io.File;
imp
In my case above suggestion does not work.
To restrict recreation of fragment, what i did:
In onCreateView
you can store inflated view in a global variable and initialize it only if it is null
, like in this code:
var root:View?=null
var apiDataReceived=false
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
if (root==null)
root=inflater!!.inflate(R.layout.fragment_layout, container, false)
return root
}
Now if you are parsing some data and fill it into RecyclerView
or any other View
Make a global variable like in above code apiDataReceived
Set it to true if you successfully parsed data.
Before apiCalls place a condition like this:
if (!apiDataReceived) { apiCalls() }
So if apiCalls() would be called only if data is not parsed.
Do your http calls and parsing or any other thing in method which called after onCreateView
like onStart
The above code is in kotlin, If you are facing any issue, let me know in comments.