Wednesday 14 January 2015

Display response from http in next activity

Show response in next activity can be done in following ways

Solution 1 response comes in string so pass whole response to next activity by using

         intent.putExtras("Key",response);
 
Solution 2 make a singleton class of getter setter , by using this class u can set and get values throughout our application .
like this

 step 1

public class SingleObject {

 //create an object of SingleObject
 private static SingleObject instance = new SingleObject();

 private String name;
 private String age;

 //make the constructor private so that this class cannot be
 //instantiated
   private SingleObject(){}

 //Get the only object available
 public static SingleObject getInstance(){
  return instance;
 }

  // here u can declare getter setter


public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getAge() {
    return age;
}

public void setAge(String age) {
    this.age = age;
}

}
 
step 2  use it in first activity like this
    
     Singleton tmp = Singleton.getInstance( ); tmp.setName("");

step 3 and in next activity like this

    Singleton tmp = Singleton.getInstance( ); String name = tmp.getName;

Solution 3 : Make a static Arraylist of hashmap and use it in any activity

or there may be more solutions .....

enjoy coding

 

No comments:

Post a Comment