我面临一个问题,即给共同的偏好带来一个变量。 我正在从联络员那里获得联系人、姓名和号码,然后将其保留到共同的偏好,以便我能够在另一个活动中利用他们建立一个数据库,但每次都把他们带到另一个活动中,在我要求名字或假问时给我打电话的次数?
页: 1 联系信息活动
id "displays the id"
name "displays name"
phone "displays phone"
第二次活动
id "displays phone number"
name "displays phone number"
phone "displays phone number"
i dont get it?
我的法典
优惠等级
public class SmsPrefs extends PreferenceActivity {
public static final String ID = "";
public static final String NAME = "";
public static final String NUMBER = "";
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.sms_pref);
iii
iii
接触胎儿
public void getContactData(Intent data){
Context context = this;
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = pref.edit();
ContentResolver cr = getContentResolver();
Uri contactData = data.getData();
Log.v("Contact", contactData.toString());
Cursor c = managedQuery(contactData,null,null,null,null);
if(c.moveToFirst()){
id = contactData.getLastPathSegment();
editor.putString(SmsPrefs.ID, id);
editor.commit();
Log.v("Contact", "ID: " + id.toString());
name = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
editor.putString(SmsPrefs.NAME, name);
editor.commit();
Log.v("Contact", "Name: " + name.toString());
if (Integer.parseInt(c.getString(c.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
Cursor pCur = cr.query(Phone.CONTENT_URI,null,Phone.CONTACT_ID +" = ?", new String[]{idiii, null);
if(pCur.moveToFirst()){
phone = pCur.getString(pCur.getColumnIndex(Phone.NUMBER));
editor.putString(SmsPrefs.NUMBER, phone);
editor.commit();
Log.v("Contact", "Phone Number: " + phone.toString());
iii
pCur.close();
iii
iii
c.close();
iii
如果在这项活动期间从共有的优惠中获得3项价值,则得到正确的价值。
第二次活动 snippet
ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name = new String ("name");
String id = new String ("id");
String phone = new String ("number");
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(v.getContext());
id = pref.getString(SmsPrefs.ID, "");
name = pref.getString(SmsPrefs.NAME, "");
phone = pref.getString(SmsPrefs.NUMBER, "");
Log.v("EditContact", "ID: " + id);
Log.v("EditContact", "Name: " + name);
Log.v("EditContact", "Phone: " + phone);
db.open();
db.deleteContact(7);
db.close();
db.open();
long _id;
_id = db.insertContact(phone, name, nColor, nVibrate, ringTonePath);
db.close();
Log.v("EditContact", "ID: " + _id);
Intent ok = new Intent(EditContact.this,Contacts.class);
startActivity(ok);
iii
iii);
i 故意理解,当只有两倍使用时,如何改变现状