Bonjour à tous,

J'ai actuellement deux activités faisant des requêtes HTTP. Sur la deuxième activité, il y a un bouton précédent. J'aimerai pouvoir revenir sur la première activité sans perdre d'informations car à l'heure actuelle je perds toutes les informations récupérées.

Première activité:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
public class GetChildrenList extends AppCompatActivity implements View.OnClickListener {
    private ArrayList<Child> childrenImeList = new ArrayList<Child>();
 
    private ListView itemsListView;
    private TextView tv_signin_success;
 
    String email;
    String password;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.get_children_list);
 
        String infos_user = (String) getIntent().getSerializableExtra("infos_user");
 
        tv_signin_success = (TextView) findViewById(R.id.tv_signin_success);
 
 
        tv_signin_success.setText("Bonjour " + infos_user + "!");
 
        itemsListView  = (ListView)findViewById(R.id.list_view_children);
 
 
        new GetChildrenAsync().execute();
    }
 
    class GetChildrenAsync extends AsyncTask<String, Void, ArrayList<Child>>  {
 
        private Dialog loadingDialog;
 
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            loadingDialog = ProgressDialog.show(GetChildrenList.this, "Please wait", "Loading...");
        }
 
        @Override
        protected ArrayList<Child> doInBackground(String... params) {
 
            InputStream is = null;
 
            int statusCode = 0;
            int id = 0;
            int age = 0;
            email = (String) getIntent().getSerializableExtra("email");
            password = (String) getIntent().getSerializableExtra("password");
            String result = null;
            String first_name = null;
            String last_name = null;
 
 
            try {
                //Http request to communicate with our system
                HttpClient httpClient = new DefaultHttpClient();
 
                HttpGet httpGet = new HttpGet();
                URI website = new URI("http://192.168.1.33:5000/childrenime/list");
                httpGet.setURI(website);
 
                String base64EncodedCredentials = Base64.encodeToString(
                        (email + ":" + password).getBytes(),
                        Base64.NO_WRAP);
 
                httpGet.setHeader("Authorization", "Basic " + base64EncodedCredentials);
 
                HttpResponse response = httpClient.execute(httpGet);
 
                statusCode = response.getStatusLine().getStatusCode();
 
                HttpEntity entity = response.getEntity();
                is = entity.getContent();
 
                BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8);
                StringBuilder sb = new StringBuilder();
 
                String line = null;
                while ((line = reader.readLine()) != null) {
                    sb.append(line + "\n");
                }
                result = sb.toString();
                String jsonResult = "{ \"children\":" + result + "}";
 
                Log.d("result1", jsonResult);
 
                //Manage JSON result
                JSONObject jsonObject = new JSONObject(jsonResult);
                JSONArray childrenArray = jsonObject.getJSONArray("children");
 
                for (int i = 0; i < childrenArray.length(); ++i) {
                    JSONObject child = childrenArray.getJSONObject(i);
                    id = child.getInt("id");
                    first_name = child.getString("first_name");
                    last_name = child.getString("last_name");
                    age = child.getInt("age");
 
                    String name = first_name + " " + last_name;
 
                    childrenImeList.add(new Child(id,name,age));
                }
 
            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
 
            return childrenImeList;
 
        }
 
        @Override
        protected void onPostExecute(final ArrayList<Child> childrenListInformation) {
            loadingDialog.dismiss();
            CustomListChildrenAdapter adapter = new CustomListChildrenAdapter(GetChildrenList.this, childrenListInformation);
            itemsListView.setAdapter(adapter);
        }
    }
}
Deuxième activité:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
public class GetLearningGoalsList extends AppCompatActivity implements View.OnClickListener {
    private ArrayList<LearningGoal> childrenLearningList = new ArrayList<LearningGoal>();
 
    private Button btn_previous;
    private ListView itemsListView;
 
    String email;
    String password;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.get_learning_goals_list);
 
        btn_previous = (Button) findViewById(R.id.btn_previous);
 
        btn_previous.setOnClickListener(this);
 
        itemsListView  = (ListView)findViewById(R.id.list_view_learning_goals);
 
 
        new GetLearningGoalsAsync().execute();
    }
 
    @Override
    public void onClick(View v) {
        Intent myIntent = new Intent(GetLearningGoalsList.this, GetChildrenList.class);
        myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(myIntent);
        finish();
        return;
    }
 
    class GetLearningGoalsAsync extends AsyncTask<String, Void, ArrayList<LearningGoal>>  {
 
        private Dialog loadingDialog;
 
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            loadingDialog = ProgressDialog.show(GetLearningGoalsList.this, "Please wait", "Loading...");
        }
 
        @Override
        protected ArrayList<LearningGoal> doInBackground(String... params) {
 
            InputStream is = null;
 
            int statusCode = 0;
            int id = 0;
            email = (String) getIntent().getSerializableExtra("email");
            password = (String) getIntent().getSerializableExtra("password");
            int idChild = (int) getIntent().getSerializableExtra("idChild");
            String json = null;
            String result = null;
            String name = null;
            String start_date = null;
            String end_date = null;
 
            try {
                //Http request to communicate with our system
                HttpClient httpClient = new DefaultHttpClient();
 
                HttpPost httpPost = new HttpPost();
                URI website = new URI("http://192.168.1.33:5000/learningchild/list");
                httpPost.setURI(website);
 
                JSONObject jsonObj = new JSONObject();
                jsonObj.accumulate("idChild", idChild);
 
                json = jsonObj.toString();
 
                StringEntity se = new StringEntity(json);
 
                httpPost.setEntity(se);
 
                String base64EncodedCredentials = Base64.encodeToString(
                        (email + ":" + password).getBytes(),
                        Base64.NO_WRAP);
 
                httpPost.setHeader("Authorization", "Basic " + base64EncodedCredentials);
                httpPost.setHeader("Accept", "application/json");
                httpPost.setHeader("Content-type", "application/json");
 
                HttpResponse response = httpClient.execute(httpPost);
 
                statusCode = response.getStatusLine().getStatusCode();
 
                HttpEntity entity = response.getEntity();
                is = entity.getContent();
 
                BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8);
                StringBuilder sb = new StringBuilder();
 
                String line = null;
                while ((line = reader.readLine()) != null) {
                    sb.append(line + "\n");
                }
                result = sb.toString();
                String jsonResult = "{ \"learningGoals\":" + result + "}";
 
                Log.d("result1", jsonResult);
 
                //Manage JSON result
                JSONObject jsonObject = new JSONObject(jsonResult);
                JSONArray learningGoalsArray = jsonObject.getJSONArray("learningGoals");
 
                for (int i = 0; i < learningGoalsArray.length(); ++i) {
                    JSONObject learningGoal = learningGoalsArray.getJSONObject(i);
                    id = learningGoal.getInt("id");
                    name = learningGoal.getString("name");
                    start_date = learningGoal.getString("start_date");
                    end_date = learningGoal.getString("end_date");
 
 
                    childrenLearningList.add(new LearningGoal(id,name,start_date,end_date));
                }
 
            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
 
            return childrenLearningList;
 
        }
 
        @Override
        protected void onPostExecute(final ArrayList<LearningGoal> learningListInformation) {
            loadingDialog.dismiss();
            CustomListLearningGoalAdapter adapter = new CustomListLearningGoalAdapter(GetLearningGoalsList.this, learningListInformation);
            itemsListView.setAdapter(adapter);
        }
    }
}
Comment pourrai-je faire pour ne pas perdre d'informations?

Merci à vous.