我无法保存此活动的状态

时间:2011-06-29 17:29:18

标签: android savestate

    public class Talk extends Activity {
private ProgressDialog progDialog;
int typeBar;
TextView text1;
EditText edit;
Button respond;
private String name;
private String textAtView;
private String savedName;


public void onCreate (Bundle onSavedInstanceState){

    super.onCreate(onSavedInstanceState);
    setContentView(R.layout.dorothydialog);
    text1 = (TextView)findViewById(R.id.dialog);
    edit = (EditText)findViewById(R.id.repsond);
    respond = (Button)findViewById(R.id.button01);

    if(onSavedInstanceState == null){


        text1.setText("Welcome! Enter your name!");
        respond.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                runDialog(2);
                name = edit.getText().toString();
                text1.setText("Cool! your name is "+name);

                respond.setOnClickListener(new View.OnClickListener() {

                    @Override   
                    public void onClick(View v) {
                        runDialog(6);   




                    }
                });

            }
        });
        }else{
            reloadState();
        }

    }
    @Override
    public void onSaveInstanceState(Bundle outState){
        super.onSaveInstanceState(outState);

        super.onSaveInstanceState(outState);


    }
    public void reloadState(){

        text1.setText(textAtView);
    }
    @Override
    public void onDestroy(){
        super.onDestroy();

    }

我知道有些人可能认为这很简单,但是我无法保存此活动的状态..如果有人会帮助我并提供基于我上面的代码的示例。非常感谢!

1 个答案:

答案 0 :(得分:0)

您需要实际保存Bundle中的数据。然后实际上从Bundle重新加载数据。你非常接近。

@Override
public void onSaveInstanceState(Bundle outState){
    super.onSaveInstanceState(outState);
    outState.putString("text1", text1.getText().toString());
}
public void reloadState(){
    text1.setText(outState.getString("text1"));
}