Tuesday, 13 June 2017

android - How do I save the state of my activity?

How do I save the way my Activity is so when closed with the backed button and resumed it will be the same way it was when closed.




this is my Activity code:



public class Levels extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);
setContentView(R.layout.levels);


final EditText anstext1 = (EditText) findViewById(R.id.anstext1);
Button button1 = (Button) findViewById(R.id.button1);

button1.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
String result = anstext1.getText().toString();
if(result.equals("they"))

setContentView(R.layout.social);
else
Toast.makeText(getApplicationContext(), "Wrong", Toast.LENGTH_LONG).show();
}
});
}
}

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...