How to save state when activity it destroyed with this

前端 未结 1 1007
醉梦人生
醉梦人生 2021-01-28 01:06
    public class Talk extends Activity {
private ProgressDialog progDialog;
int typeBar;
TextView text1;
EditText edit;
Button respond;
private String name;
private Stri         


        
相关标签:
1条回答
  • 2021-01-28 01:31

    For the second thing

    This should work:

    public class TestActivity extends Activity implements Runnable, OnClickListener {
    private TextView tv;
    private ProgressDialog pd;
    private Button btn;
    
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);
    
        tv = (TextView) this.findViewById(R.id.tv);     
        btn = (Button)findViewById(R.id.btn);
    
        tv.setText("initial text");
    
        btn.setOnClickListener(this);
    }
    
    public void onClick(View v) {
        pd = ProgressDialog.show(TestActivity.this, "Please wait...", "Details here", true, false);
    
        Thread thread = new Thread(TestActivity.this);
        thread.start();
    }
    public void run() {
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    
        handler.sendEmptyMessage(0);
    }
    
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            pd.dismiss();
            tv.setText("text after 5 sec passed");
        }
    };
    }
    
    0 讨论(0)
提交回复
热议问题