Make a generic Result receiver
You can create an interface for this task which would fetch a String data from any Activity to your Fragment. Follow these steps.
Create an interface
public interface MyResultReceiver{
public String getResult();
}
Make MyResultReceiver
a member of your Fragment
public class tabquests extends Fragment{
public CheckBox lc;
public MyResultReceiver resultreceiver;
@Override
public void onAttach(Context context){
super.onAttach(cotext);
resultreceiver = (MyResultReceiver)context;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)//onCreateView
{
YourFragment code code
Boolean result = resultreceiver.getResult();
lc.setChecked(result);
}
}
Implement MyResultReceiver
in the Activity and override the method
public class tabsmain extends Activity implements MyResultReceiver{
public boolean lf_ch=false;
// Activity code
@Override
public boolean getResult(){
return lf_ch;
}
}
Disclaimer:
You might find it a bit lengthy for this case. But the plus point of this approach is that if you want to reuse this code for another activity. You will not have to write the same logic again. Just implement the MyResultReceiver
in your activity , override the method and your will be good to go.
TIP: To be able to get any kind of data, change the method definition in the interface
from public String getResult();
to public Object getResult();