English 中文(简体)
共同优惠问题
原标题:shared preferences problem

我面临一个问题,即给共同的偏好带来一个变量。 我正在从联络员那里获得联系人、姓名和号码,然后将其保留到共同的偏好,以便我能够在另一个活动中利用他们建立一个数据库,但每次都把他们带到另一个活动中,在我要求名字或假问时给我打电话的次数?

页: 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 故意理解,当只有两倍使用时,如何改变现状

最佳回答

页: 1 SmsPrefs.ID,.NAME。 NUMBER值相同。 它们需要不同,或相互重叠。

你可以:

  • Change the order in which you write the data, writing the phone number before the name and id. This should alter your results and confirm the problem.
  • Step through the app in the debugger to see what the actual values of those constants are
  • Post your SmsPrefs code for us to investigate.

更改<代码>SmsPrefs a. 用于:

public static final String ID = "com.example.SmsPrefs.ID";
public static final String NAME = "com.example.SmsPrefs.NAME";
public static final String NUMBER = "com.example.SmsPrefs.NUMBER";

你的钥匙实际上必须彼此不同。

问题回答
public static final String ID = "";
public static final String NAME = "";
public static final String NUMBER = "";

这些问题需要确定为:

public static final String ID = "_id";
public static final String NAME = "_name";
public static final String NUMBER = "_number";




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签