Saving JsonReuest data on change of orientation

80 views Asked by At

I am building a Test Application in Android, the problem is when I change the orientation of the screen it the fragment is loaded again and the data is gone that is requested from Json.

Here is request code

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    String testDetailUrl = "http://www.json-generator.com/api/json /get/cqZnauiJbC?indent=2";
    ((TrikshaApplication) parentActivity.getApplication()).setTestTime(0);
    TaskResponseListener taskResponseListener = new TaskResponseListener();
    JsonRequest messageRequest = new JsonRequest(testDetailUrl, testQuestions[].class,
            taskResponseListener, taskResponseListener);
    uiHandler = new Handler();
    arrayList = new ArrayList<String>();
    if (!((TrikshaApplication) parentActivity.getApplication()).getCallingFragment().equals("Shiksha")) {
        timeLimitLauncher = new TimeLimitLauncher();
    }

    this.getServiceLocator().getRequestQueue(getActivity()).add(messageRequest);

}

Here is on configuration change code

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    LayoutInflater inflater = LayoutInflater.from(getActivity());
    populateViewForOrientation(inflater, (ViewGroup) getView());
    getActivity().setContentView(R.layout.fragment_test_question_ans_layout);
}

private void populateViewForOrientation(LayoutInflater inflater, ViewGroup viewGroup) {
     viewGroup.removeAllViewsInLayout();
     View subview = inflater.inflate(R.layout.fragment_test_question_ans_layout, viewGroup);

}

Here is the change that I have done in manifest file for activity

android:configChanges="orientation|screenSize|keyboardHidden"

Here is the link of screenshot before orientation change http://s3.postimg.org/gjfws3nxv/Screenshot_2015_06_12_12_08_02.png

After orientation change http://s4.postimg.org/86fgaxrwd/Screenshot_2015_06_12_12_08_08.png

I have made two layouts one for portrait and one for landscape in layout-land folder.

0

There are 0 answers