0

enter image description here

THis is the result i get after i login to the server. the main things i want to do is, after it login and will open another page which will list out all the data to another activity named MainActivity.

public void showJSON(String json){
    ParseJson pj = new ParseJson(json);
    pj.parseJson();
    EventList cl = new EventList(this, ParseJson.ids,ParseJson.titles,ParseJson.descriptions);
    listViewMain.setAdapter(cl);
}

I try to put this code inside my MainActivity, and called it from LoginActivity:

public void onResponse(String response) {
                        if(response.trim().equals("Login failed. Please enter the correct information.")){
                            Toast.makeText(Login.this, response, Toast.LENGTH_LONG).show();

                        }else{
                            MainActivity test = new MainActivity();
                            test.showJSON(response);
                        }
                    }

But it got the error which is no responding. The main purpose is i want to get the data and put into my MainActivity listview. What method should i try after login and get the data in my another activity.

Ben
  • 443
  • 4
  • 16

1 Answers1

0

What you are doing is correct, get the data in login activity and then pass it to Main activity using intent With intent.putextra, you can set your data and call your next activity. For details see below link.

http://developer.android.com/reference/android/content/Intent.html

Ashish Rawat
  • 5,541
  • 1
  • 20
  • 17
  • Thanks, i am quite new in this area. So this make me confuse. – Ben Feb 01 '16 at 04:27
  • No prob, just keep the list in main activity and you can pass data as mentioned above. – Ashish Rawat Feb 01 '16 at 04:28
  • So put the showJSON inside mainactivity is ok? But the data doesnot pass into the Mainactivity and cause it fail – Ben Feb 01 '16 at 04:31
  • `public void parseData(String json){ // Toast.makeText(Login.this, json, Toast.LENGTH_LONG).show(); Intent intent = new Intent(this, MainActivity.class); intent.putExtra("data",json); startActivity(intent); }` Is that what you mean? – Ben Feb 01 '16 at 06:07