有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在onpause中保存int

public class excuse extends Activity{
    String excuse[] = { "1", "2","3", "4", "5", "6","7","8", "9","10" };
    Button re;
    Button pre;
    TextView dis;
    int counter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.excuse);        
        re = (Button)findViewById(R.id.button1);
        pre = (Button)findViewById(R.id.button2);
        dis = (TextView)findViewById(R.id.textView1);
        counter = 0; 
        counter = counter + 1;
        dis.setText( " hi" + counter );
        counter = counter + 1;
    }
    @Override
    protected void onPause() {
        super.onPause();        
    }
}

如何将counter保存到某个地方,以便在它更改活动并返回时知道counter被关闭了?此外,我还省略了按钮功能以节省空间。还有,这方面有教程吗


共 (1) 个答案

  1. # 1 楼答案

    有关“如何在运行之间保存一些数据”的更一般的答案,请查看Storage Options Guide。最容易使用的可能是共享首选项