Skip to content
Advertisement

TextView lost after onPause()

I’m learning how to add elements to LayoutParam. I add a TextView element after each click to “`LayoutParam“.

public void send(View v){
        message=edt.getText().toString().trim();
        if(!message.equals("")){
            TextView txt = new TextView(this);
            txt.setText("You: "+message);
            txt.setPadding(10,10,10,10);
            txt.setTextSize(20);
            txt.setTextColor(Color.WHITE);
            txt.setFreezesText(true);
            llayout.addView(txt);
            scroll.fullScroll(View.FOCUS_DOWN);
            edt.setText("");
        }
    }
    

my problem is when i press the Home Button and i open the app again, i don’t see any elements. as they have never been.

Advertisement

Answer

Are you recalling the send() method in the onResume() method? if not then the data you had will be lost once the activity/fragment resumes. You would need something like this inside onResume():

@Override
public void onResume(){
    super.onResume();
    send(new View());
}

The parameters inside send, will be whatever view you’re passing in.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement