1
Good, I’m new to Android, but I would like to know how I can keep/save the information that is in a Textview, so that this is not deleted when close application.
public class Activity extends AppCompatActivity {
Calendar c = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd:MMMM:yyyy HH:mm:ss");
String strDate = sdf.format(c.getTime());
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
EscreverData();}
private void EscreverData(){
TextView datas = (TextView) findViewById(R.id.datas);
datas.append(strDate);}}
Basically what I want is, when this activity starts, get the date and time and show this information in Textview. However, I would like her to continue storing the old dates and not erase them each time the activity is started again. I’ve tried searching a little and I think a good solution could be Sharedpreferences but I don’t know how to use it. Thanks if you can help me
Do you already have any code? It would be interesting if you put it here to help us identify the solution (https://answall.com/help/mcve).
– rLinhares
Do a Sharedpreferences search.
– Márcio Oliveira
@Here you go... if you can help me, I’d appreciate it
– Eduardo Brito