-2

if I have a string in activityA, how can I modify this string in another activity (for example activityB)???

Note: I don't want to passing data from one activity to another, so I don't won't the copy of the string, but the real string of activityA in activity B

1 Answers1

3

One option is to make the variable global. For example (these classes are in two separate files):

public class A {
    public static String s = "A";
    //...
}

public class B {
    //...

   public static void vandalizeClassA() {
       System.out.println(A.s); //output will be "A"
       A.s = "B was here"; 
       System.out.println(A.s); //output will be "B was here"
   }
}

This is not specific to Android activities.

Zarwan
  • 5,537
  • 4
  • 30
  • 48