T
TheAngelsCry
Guest
Okay, I've been charged with creating an SMS application for my College Project, however, I've run into a few difficulties.
I'm able to store text in a shared preferences in my Settings.java, and the information recalls perfectly when the program is paused and then restarted - so I know that code works.
My problem is that when I want to display this information AGAIN in a different file (Send.java) it's not working. Any ideas what I'm doing wrong?
Any help would really be appreciated! ^_^
I'm able to store text in a shared preferences in my Settings.java, and the information recalls perfectly when the program is paused and then restarted - so I know that code works.
My problem is that when I want to display this information AGAIN in a different file (Send.java) it's not working. Any ideas what I'm doing wrong?
Settings.java said:package sms.project;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Settings extends Activity implements OnClickListener {
private Button settingsBtnBack;
public EditText txtInitial;
public EditText txtSurname;
public EditText txtEmail;
public SharedPreferences prefsInitial;
public SharedPreferences prefsSurname;
public SharedPreferences prefsEmail;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
settingsBtnBack = (Button)findViewById(R.id.settingsBtnBack);
settingsBtnBack.setOnClickListener(this);
prefsInitial = getPreferences(MODE_WORLD_READABLE);
txtInitial = (EditText)findViewById(R.id.shinitial);
String initial = prefsInitial.getString("initial","");
txtInitial.setText(initial);
txtSurname = (EditText)findViewById(R.id.shsurname);
String surname = prefsInitial.getString("initial","");
txtSurname.setText(surname);
prefsEmail = getPreferences(MODE_WORLD_READABLE);
txtEmail = (EditText)findViewById(R.id.shemail);
String email = prefsEmail.getString("email","");
txtEmail.setText(email);
}
public void onClick(View v) {
if (v==this.settingsBtnBack) {
Intent i = new Intent(this, Main.class);
startActivityForResult(i, 1);
Toast.makeText(getApplicationContext(), "Settings Saved", Toast.LENGTH_SHORT).show();
}
}
public void onPause() {
super.onPause();
SharedPreferences.Editor i = prefsInitial.edit();
String initial = String.valueOf( txtInitial.getText() );
i.putString("initial", initial);
i.commit();
SharedPreferences.Editor e = prefsEmail.edit();
String email = String.valueOf( txtEmail.getText() );
e.putString("email", email);
e.commit();
}
}
Send.java (My problem area) said:package sms.project;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Send extends Activity implements OnClickListener {
private Button sendBtnBack;
public EditText sendcheckmessage;
public SharedPreferences prefsInitial;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.send);
sendBtnBack = (Button)findViewById(R.id.sendBtnBack);
sendBtnBack.setOnClickListener(this);
sendcheckmessage = (EditText)findViewById(R.id.sendcheckmessage);
String check = prefsInitial.getString("initial","");
sendcheckmessage.setText(check);
}
public void onClick(View v) {
if (v==this.sendBtnBack) {
Intent i = new Intent(this, Main.class);
startActivityForResult(i, 1);
Toast.makeText(getApplicationContext(), "To Be Coded", Toast.LENGTH_SHORT).show();
}
}
}
Any help would really be appreciated! ^_^