私のアプリケーションはまだクラッシュしています私は知りません
共通の好みがあるからだと思います
Aアクティビティで、Bアクティビティに保存された共有設定をロードします
そして、アプリケーションは最初に起動されたときに強制的に閉じられました
これが私のAアクティビティです:
public class DawaaActivity extends Activity implements View.OnClickListener {
/** Called when the activity is first created. */
Button add;
SharedPreferences emportPref = this.getSharedPreferences("dawaaData",MODE_PRIVATE);;
String meDawaa = emportPref.getString("subject", "no data yet");
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Toast.makeText(DawaaActivity.this, meDawaa , Toast.LENGTH_SHORT).show();
initialaiz();
}
private void initialaiz() {
// TODO Auto-generated method stub
add = (Button) findViewById(R.id.button3);
add.setOnClickListener(this);
}
public void onClick(View v) {
// TODO Auto-generated method stub
Intent data = new Intent(DawaaActivity.this,SettingActivity.class);
startActivity(data);
}
}
これは私のBアクティビティです:
public class SettingActivity extends Activity implements View.OnClickListener {
EditText et;
EditText et1;
Spinner list;
TimePicker startTime;
Button save;
Button cancel;
private SharedPreferences exportPref;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.setting);
initialaiz();
}
private void initialaiz() {
// TODO Auto-generated method stub
et = (EditText) findViewById(R.id.text);
et1 = (EditText) findViewById(R.id.text1);
list = (Spinner) findViewById(R.id.spinner);
startTime = (TimePicker) findViewById(R.id.timePicker);
save = (Button) findViewById(R.id.save);
cancel = (Button) findViewById(R.id.cancel);
save.setOnClickListener(this);
cancel.setOnClickListener(this);
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.save:
save();
Intent transferData = new Intent(SettingActivity.this,DawaaActivity.class);
startActivity(transferData);
break;
case R.id.cancel:
finish();
break;
}
}
public void save() {
// TODO Auto-generated method stub
exportPref = getSharedPreferences("dawaaData",MODE_PRIVATE);
SharedPreferences.Editor editor = exportPref.edit();
editor.putString("subject", et.getText().toString());
editor.putString("dosesC", et1.getText().toString());
editor.putString("doses", list.getSelectedItem().toString());
editor.putInt("hour", startTime.getCurrentHour());
editor.putInt("minute", startTime.getCurrentMinute());
editor.putInt("exists", 1);
editor.commit();
Toast.makeText(SettingActivity.this,"data has been saved" ,Toast.LENGTH_SHORT).show();
}
}
私たちを手伝ってくれますか??