1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Save string/EditText in memory android studio

Discussion in 'Programming' started by Yakov Cohen, Jul 7, 2021.

  1. #1
    I have a problem with save the value of string or editText in java android. When I redirect from FirstActivity to Second and return after it to First, I need that a String that i fill earlier stay in the place that I wrote it. (Like a cookies in js).
     
    Solved! View solution.
    Yakov Cohen, Jul 7, 2021 IP
  2. #2
    If you want to persist data like cookies, use Shared Preference. Here's a sample
    //Store text
    SharedPreferences sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
    
    SharedPreferences.Editor editor = sharedpreferences.edit();
    editor.putString("textKey", editText.getText().toString());
    editor.commit();
    
    //Get the data from Shared Preferene
    sharedpreferences.getString("textKey", null);
    Code (markup):
    But if you are just navigating between 2 screens, you should not have to do all that because the screens are not destroyed when you navigate out. Unless you call finish();
     
    Efetobor Agbontaen, Jul 7, 2021 IP
  3. derhau

    derhau Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    I definitely disapprove of save the benefit of string or editText in java android. At the point when I divert from FirstActivity to Second and return after it to First, I want that a String that I fill prior stay in the spot that I composed it. (Like a treats in js).
     
    derhau, Jul 16, 2022 IP